Tuesday 22 March 2011

How to get the current row in GridView command event?

I have a LinkButton element in the gridview and I need to raise the grid view command event when the user clicks the link button and in that event, I need to get the row values.

The solution for this question is as follw:

GridViewRow row = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;

Note: If your requirement is not linkbutton then please place the corresponding control name. There are lot of advantages with this property. Especially when we write and render controls to page dynamically then this property will help a lot.

No comments:

Post a Comment