Buttons in a grid

  • Thread starter Thread starter Edward W.
  • Start date Start date
E

Edward W.

Let's say I have a dataset with 1 table and it has 3 columns. One of the
columns is a primary key. The number of rows is unknown, but for
simplicity's sake let's say anywhere from 5 to 50 rows. I want to fill a
grid on screen and in each row add a new column and in that column put a
command button. I want every button to have the same event when clicked.
How do I do this so that when the button is clicked but in the click event I
at least get the primary key of the column in the row so that I can uniquely
identify that row?

Thank you.
 
Edward,

The datagrid comes with editing, updating, cancelling and deleting events
for just this purpose...

The basic principle is that a click then passes back the item (row) that was
clicked. From here you can examine any of the rows details (for id numbers
etc), and perform what ever action you want on that row... All this is done
around one event handler method.

Check out:
http://msdn.microsoft.com/library/d...y/en-us/dnaspp/html/creatingcustomcolumns.asp
http://aspnet.4guysfromrolla.com/articles/071002-1.aspx

Let me know if you need any help...

Dan.
 
Edward, plenty of good articles like the ones Dan mentions. In the case where
the user won't see your key field (e.g. ID), you have a few options: a) use
datakeyfield, b) use a hidden column in the grid, or c) assign the ID to the
CommandArgument attribute of the button. I always use one of these methods so
I'm not forced to display the ID if I don't want to. It's also helpful in
cases where the ID you show is not the same ID you'd pass to a new page (e.g.
you might want to pass an encrypted version of the ID if the user is going to
see it in a query string, etc.).
 
cast the sender object of the event handler to a datagridItem and then you
can access the rows and columns of the datagrid to determine the value
 
Back
Top