Row Index in RowCommand event handler

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a gridview that has a button column and a template column with another
button in it. When I click on the button column button I can get the row
index in the event handler for the CommandArgument parameter. However when I
click on the template column button the CommandArgument parameter is "".

How can I get the row index when a user clicks on a button in a template
column?

Thanks,
James
 
Hi,

I guess you have to put it inthe Command argument :)
What I usually do is put the "id" or key inthe ComandArgument. I have never
put the column index. I'mpretty sure you can get a hold of it using binding.
Otherwise you have to use ItemDataBound method.
 
How would you set the command argument to an ID or Key? I am simply binding
to a datatable.

James
 
I found the solution there is two ways to set it

1) <asp:Button (...) CommandArgument="<%# Container.DataItemIndex %>" />
2) In the row created event handler.
 
Back
Top