Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > How to add multiple buttons to a datagrid row... and handle their events

Reply
Thread Tools

How to add multiple buttons to a datagrid row... and handle their events

 
 
AC
Guest
Posts: n/a
 
      12-29-2003
I have a DataTable that I'm currently displaying in a DataGrid... but I have the case where I need to use multiple buttons/linkButtons in each row of the DataGrid (in non-edit mode) so I can manually control the sorting and to remove items from the DataTable.

Using template columns, I can easily add buttons to one column and assign them unique ID's, but I can't seem to create the event handlers on the server side. It seems that the codebehind can't understand the unique names of the button names (well, they are unique in the column, but when the control is rendered, they'd all have the same name [I know ASP.NET gives them unique IDs] and I'm just using the CommandArgument to pass the unique value back to me).

In the past, when I've only needed one button, I've just added the Edit button and before the EditCommand method finished, I would just set the EditItemIndex back to -1 so it never got into Edit mode. I knew this was a hack, but it worked and I always meant to revisit this, but never had the time. Well, now I not only have the time, but I'm forced into a corner.

Granted, I might be using the wrong control... maybe I should be using the DataList. Has anyone had this need? I've sort of seen posts about this when people need to add multiple controls to a templte column when in EditMode, but I am not in edit mode.

Thanks
-AC
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      01-01-2004
Hi,

you can put Button/LinkButton/ImageButtons to rows and specify them the
CommandName and CommandArgument attributes. When this kind of control is
clicked, ItemCommand event of the Datagrid is raised with the given
arguments (that were specified in the clicked Button). That way you can know
which button was clicked and you don't have to specify event handlers for
Click events.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"AC" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
I have a DataTable that I'm currently displaying in a DataGrid... but I have
the case where I need to use multiple buttons/linkButtons in each row of the
DataGrid (in non-edit mode) so I can manually control the sorting and to
remove items from the DataTable.

Using template columns, I can easily add buttons to one column and assign
them unique ID's, but I can't seem to create the event handlers on the
server side. It seems that the codebehind can't understand the unique names
of the button names (well, they are unique in the column, but when the
control is rendered, they'd all have the same name [I know ASP.NET gives
them unique IDs] and I'm just using the CommandArgument to pass the unique
value back to me).

In the past, when I've only needed one button, I've just added the Edit
button and before the EditCommand method finished, I would just set the
EditItemIndex back to -1 so it never got into Edit mode. I knew this was a
hack, but it worked and I always meant to revisit this, but never had the
time. Well, now I not only have the time, but I'm forced into a corner.

Granted, I might be using the wrong control... maybe I should be using the
DataList. Has anyone had this need? I've sort of seen posts about this
when people need to add multiple controls to a templte column when in
EditMode, but I am not in edit mode.

Thanks
-AC


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Datagrid Nav buttons and numeric buttons Jeremy Jones ASP .Net 1 03-22-2007 08:00 AM
how to handle multiple events from a control collection? Yahoo ASP .Net Web Controls 0 11-04-2005 08:03 PM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
What the pros use to power their flashes... and their digital cameras. Dan Sullivan Digital Photography 21 01-04-2004 04:40 PM



Advertisments