Which button was clicked and on which row?

Y

Yossi

I have GridView with several text columns and 2 buttons. How do I determine
which button on which row was clicked.

I am able to detect a button clicked if I set the CommandText to "Select".
All I have to do is write an event handler for the SelectedIndexChanged
event and I get to know on which row the button was clicked. But how do I
tell whether the first or second buttons where clicked?
 
Y

Yossi

I found the answer in the MSDN:

To determine the index of the record that raises the command event, use the
CommandArgument property of the event argument that is passed to the command
event for the data-bound control. The ButtonField class automatically
populates the CommandArgument property with the appropriate index value.

Intellisense was not showing me a CommandArgument. That is why I got
confused. Now all I have to do is set different CommandNames for each
button in order to determine which one was clicked. Before, I set the
CommandName of both buttons to Select and then I was handling the
OnSelectedIndexChanged event. That was giving me the row, but not which
button fired the select.
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top