Rocky
Rocky

Reputation: 4524

how to get row index on btn click which is out side of the grid

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

Answers (1)

Csujo
Csujo

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

Related Questions