HighTechTalks DotNet Forums  

Dynamically creating buttons per row: how?

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss Dynamically creating buttons per row: how? in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
who be dat?
 
Posts: n/a

Default Dynamically creating buttons per row: how? - 06-24-2004 , 09:54 AM






I'm working on a web application that will use some datagrid and asp.net, an
asp.net Forum to be exact where people can leave posts and respond to posts
others have left. One page in particular displays rows with an
"interesting" column. What's interesting about this column is that it
displays some links followed by text (the message someone left), all in the
same column. These links represent actions a user can do. One link lets a
user reply to a message, the other link lets a user quote a message, link #3
lets a user delete a message, while the fourth link let's a user edit a
message. I'd like for these links to be buttons so I can put some code
behind them.

I'm relatively new to ASP.Net although I'm picking it up fairly well.
Datagrids in particular are giving me a bit of a fit although I'm slowly
learning the in's and out's of them. However, I've hit of a bricj wall. I
think I can do what I want with templates and such. When a button is
called, I can catch this event using the ItemCommand event and write the
necessary code to deal with what was clicked. Two problems I'm having:

1) All four buttons are not shown for each row everytime. At a minimum, a
row will display only two buttons, the reply and quote buttons. Edit will
only show up if the user who is logged in created the message for that
particular row. If the user didn't create that message in a given row, then
that user shouldn't see an edit button for that message. The delete button
works in a similar fashion although there are conditions where others can
delete a message. The point is, there are a total of four buttons that
maybe visible for each row but on some rows only 2 or 3 buttons will be
shown.

2) Due to the fact I like the way things look, I prefer to put the buttons
and text in the same column. Essientlly, the buttons will be at the top of
a column with the text of a message shown below the buttons, again in the
same column.

I suppose if I have to, I can put the buttons in their own column and have
the text in a seperate column, but I'd rather have them both in the same
column while figuring out a way to have buttons present or not present on a
per row basis.

Is this possible? I've seen quite a few examples of adding controls (such
as buttons) to a column, but I've never seen an example where each row could
have a different amount of buttons in the same column unless the datagrid
has gone to edit mode for a row, for example, which I'd rather not do.
Plus, I'm not seeing much where it comes to adding controls and adding text
after a control although I suppose I could add a label after the buttons in
the column and fill it with the text representing the message...

Any thoughts on this would be greatly appreciated. I ordered an ASP.Net
book on controls which was recommended on DatagridGirl.com, but it won't be
here for a day or two. I'd really like to get past this ASAP.

Sorry for the long post and thanks!

Chris Smith



Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default Re: Dynamically creating buttons per row: how? - 06-24-2004 , 11:43 AM






You can dynamically create controls in the itemdatabound event.
Create a empty template column as a container for your buttons and
onitemdatabound you can create buttons and add them to the cell.

-Adam


Reply With Quote
  #3  
Old   
who be dat?
 
Posts: n/a

Default Re: Dynamically creating buttons per row: how? - 06-24-2004 , 12:05 PM



Ahhh.... OK. This sounds like a good beginning. I think I fully
understand what you are saying.

Would it be possible to put text after these controls so everything could be
in one column? I suppose I could put a label in after after the buttons and
set it's text property to the text of the message to be displayed...

Chris Smith

<ashelley (AT) inlandkwpp (DOT) com> wrote

Quote:
You can dynamically create controls in the itemdatabound event.
Create a empty template column as a container for your buttons and
onitemdatabound you can create buttons and add them to the cell.

-Adam




Reply With Quote
  #4  
Old   
AT
 
Posts: n/a

Default Re: Dynamically creating buttons per row: how? - 06-24-2004 , 02:09 PM



On Thu, 24 Jun 2004 12:05:55 -0400, "who be dat?" <whatever (AT) dot (DOT) com>
wrote:

Quote:
Ahhh.... OK. This sounds like a good beginning. I think I fully
understand what you are saying.

Would it be possible to put text after these controls so everything could be
in one column? I suppose I could put a label in after after the buttons and
set it's text property to the text of the message to be displayed...

yes, exactly. You can use a label or even a literalcontrol.

-Adam


Reply With Quote
  #5  
Old   
who be dat?
 
Posts: n/a

Default Re: Dynamically creating buttons per row: how? - 06-26-2004 , 09:32 PM



Alright, I got it to add the buttons that I wanted just as you said to do.
However, thing is they don't do anything!! I put in an ItemCommand event
handler in my code to handle the buttons when they were clicked. Thing is,
it never even goes to the ItemCommand subroutine. Well, unless I click a
page at the bottom of the grid to go to a different page. It doesn't use
the PageIndexChanged even anymore, it goes to ItemCommand. Not a huge deal,
I can check the commandname which is "page" when you want to go to a
different page. I can put the code for a new page in an if/end if block.
However, none of the buttoms ever make it to the ItemCommand event.

I used trace to follow the code execution. Once the page is loaded, I can
click a new page in the footer. The path of the execution automatically
goes to ItemCommand, doesn't start at any other place, just right at this
event handler. However, when I click a button it doesn't go to Itemcommand
even handler. Instead, clicking a button acts like it's just posting back
to the page. The code immediately goes back to the load_page event. Since
it's a postback, the page is just redisplayed.

Good news: I can insert buttons and I can insert/not insert the buttons that
I need or want on a per row basis. Bad news, they don't do anything. I've
tried everything I can think of and tried to figure out why, but I'm at a
loss to explain it. Any ideas? Hope you are still there. Thanks!

Chris Smith



<ashelley (AT) inlandkwpp (DOT) com> wrote

Quote:
On Thu, 24 Jun 2004 12:05:55 -0400, "who be dat?" <whatever (AT) dot (DOT) com
wrote:

Ahhh.... OK. This sounds like a good beginning. I think I fully
understand what you are saying.

Would it be possible to put text after these controls so everything could
be
in one column? I suppose I could put a label in after after the buttons
and
set it's text property to the text of the message to be displayed...


yes, exactly. You can use a label or even a literalcontrol.

-Adam



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.