Row index for a link button in a grid
-
How can I find the row index when a linkbutton is clicked within a grid?
Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand e.CommandArgument does not give me the row index. Thanks, Martin -
How can I find the row index when a linkbutton is clicked within a grid?
Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand e.CommandArgument does not give me the row index. Thanks, MartinMicrosoft help suggest setting it in the row create:
Sub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
' The GridViewCommandEventArgs class does not contain a ' property that indicates which row's command button was ' clicked. To identify which row's button was clicked, use ' the button's CommandArgument property by setting it to the ' row's index. If e.Row.RowType = DataControlRowType.DataRow Then ' Retrieve the LinkButton control from the first column. Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton) ' Set the LinkButton's CommandArgument property with the ' row's index. addButton.CommandArgument = e.Row.RowIndex.ToString() End If
End Sub
Hope that helps Ben
-
Microsoft help suggest setting it in the row create:
Sub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
' The GridViewCommandEventArgs class does not contain a ' property that indicates which row's command button was ' clicked. To identify which row's button was clicked, use ' the button's CommandArgument property by setting it to the ' row's index. If e.Row.RowType = DataControlRowType.DataRow Then ' Retrieve the LinkButton control from the first column. Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton) ' Set the LinkButton's CommandArgument property with the ' row's index. addButton.CommandArgument = e.Row.RowIndex.ToString() End If
End Sub
Hope that helps Ben