ASP.NET’s GridView control suffers from an irritating design flaw. When a GridView contains a ButtonField and one of the buttons in the column is clicked, there’s no obvious way to determine WHICH button was clicked–that is, to get a reference to the row containing the clicked button. I’ve seen all kinds of work-arounds, some better than others, but here’s the one I use:
GridViewRow row = (GridViewRow) ((WebControl)e.CommandSource).Parent.Parent;
Place this line of code inside a RowCommand handler and “row” is initialized with a reference to the GridViewRow whose button was clicked.