Saturday, March 3, 2018

Get the Gridview row, row index which fired the RowCommand event

Here is the code snippet:

Public Sub gvTestGrid_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvTestGrid.RowCommand
Dim gvr As GridViewRow = CType(CType(e.CommandSource, LinkButton).NamingContainer,           GridViewRow)
Dim rowIndex As Integer = gvr.RowIndex
//Make a label visible in this row
CType(gvr.FindControl("UserSelected"), Label).Visible = True
End Sub


This assumes you have ItemTemplate column in your GridView (gvTestGrid) containing a label with Id="UserSelected" which is hidden by default.

No comments:

Post a Comment