Retreiving a DataItem in the GridView's RowCommand

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I have a GridView with a ButtonField. In the RowCommand I need to use the
value of one of the fields used in that row. I am having trouble doing this,
so I would appreciate it if someone could help me here. Thanks.
 
This is a ButtonField, and the reason I need the value is so that I know
what SQL statement to execute on the database. The value is not being used
for display, it is being used for functionality. The RowDataBound event will
not help me here because I need to use the value in the RowCommand event, so
I need a way to access the data from the current row.
 
This is a ButtonField, and the reason I need the value is so that I know
what SQL statement to execute on the database. The value is not being used
for display, it is being used for functionality. The RowDataBound event will
not help me here because I need to use the value in the RowCommand event, so
I need a way to access the data from the current row.









- Show quoted text -

Hi

There a various ways of doing this but if you require the primary key
then use the DataKeys property of the GridView control. Also make sure
that DataKeyNames is set correctly (it's available in the designer).

Other than that the Button control could have its CommandArgument
property bound to the required column name. Set the CommandName
property of the button control to something distinctive and then
process the click event in the GridViews RowCommand where the "e"
parameter will have those same properties set accordingly - you can
then detect it by checking the e.CommandName property and then
e.CommandArgument will then return the required value of the field.

HTH
 
Back
Top