GridView OnSelectedIndexChanged event not firing

前端 未结 6 2245
谎友^
谎友^ 2020-12-16 19:10

I am trying to get the selected row of the GridView, and I know that I should be able to get that information based on the OnSelectedIndexChanged e

6条回答
  •  孤街浪徒
    2020-12-16 19:41

    It is NOT true that you can't click a row and have it handle the SelectedIndexChanged event. You just have to add a little code to the RowCreated event.

    Protected Sub yourDataGrid_RowCreated(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles yourDataGrid.RowCreated
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes("onclick") = Me.Page.ClientScript.GetPostBackEventReference(Me.yourDataGrid, "Select$" & e.Row.RowIndex)
        End If
    End Sub
    

提交回复
热议问题