Row Index in RowCommand event handler

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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.
 
G

Guest

How would you set the command argument to an ID or Key? I am simply binding
to a datatable.

James
 
G

Guest

I found the solution there is two ways to set it

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top