Index of GridView Row clicked

  • Thread starter Abhishek Tripathi
  • Start date
A

Abhishek Tripathi

I have a gridview which has a custom buttonfield. I have written
appropriate code in the GridView1_RowCommand function. How can I find
the number of row from which the event is being generated? For example,
how can I know if the user clicked on the 2nd row of the gridview ?
Gridview1.selectedIndex returns -1 . Kindly assist
 
O

online24365

Hello,

Here is the code. I have taken a GridView with two columns. First is
ButtonField type to which assigned CommandName as "Select" and second
column is BoundText type.

private void CustomersGridView_RowCommand(Object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow =
CustomersGridView.Rows[index];
string strValue = selectedRow.Cells[1].Text;
Response.Write(strValue);
}
}
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top