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.
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;
精彩评论