Reputation: 4524
I have a button out of GridView. I want to get the row index on that button click. How to get it?
I used
GridViewRow row = ((Button)sender).Parent.Parent as GridViewRow;
but it's not working.
Upvotes: 0
Views: 2156
Reputation: 507
If the Button out of the GridView the Button parent is an other container (maybe a Form or a Panel) not the GridView.
First of all you need a reference to the GridView. If you have a variable what contains this reference you should use that. If you haven't variable, you should search the GridView:
GridView grd = this.FindControl("GridViewName");
After that you can get the GridViewRow:
GridViewRow row = grd.SelectedRow;
Upvotes: 1