2

以下は、個々のセルを選択するために使用するコードです。ただし、そのセルを選択すると、そのセルのデータ、rowIndex および columnIndex が必要になります。残念ながら、すべての調査と他のコードの試行の後.. gridView で選択したセルの columnIndex を取得する方法に行き詰まっています。

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
    For i As Integer = 0 To grdResults.Rows.Count - 1
        ClientScript.RegisterForEventValidation(grdResults.UniqueID, "Select$" & i)
    Next

    MyBase.Render(writer)
End Sub

Protected Sub grdResults_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdResults.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then

        For i As Integer = 1 To e.Row.Cells.Count - 1

            e.Row.Cells(i).Attributes("OnMouseOver") = "ToggleHighlight(this, true);"
            e.Row.Cells(i).Attributes("OnMouseOut") = "ToggleHighlight(this, false);"
            e.Row.Cells(i).Style("cursor") = "hand"
            e.Row.Cells(i).Attributes("onclick") = ClientScript.GetPostBackEventReference(grdResults, "Select$" & e.Row.RowIndex)
            e.Row.Cells(i).Attributes("style") += "cursor:pointer;curosor:hand;"
        Next
    End If
End Sub

Protected Sub grdResults_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdResults.SelectedIndexChanged
    LoadDetails(columnIndex, grdResults.selectedRow)
End Sub

これも私が試したことです

* commandName "ColumnClick" で buttonField をやってみました。次に、grdResults_RowCommand を使用して rowIndex と columnIndex を取得しようとしますが、enableEventValidation エラー ページが表示されます。次のようなオーバーライドされたレンダリングがありますが、

'Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
'    For Each r As GridViewRow In grdResults.Rows
'        If r.RowType = DataControlRowType.DataRow Then
'            For columnIndex As Integer = 0 To r.Cells.Count - 1
'                ClientScript.RegisterForEventValidation(r.UniqueID + "$ct100", columnIndex.ToString())
'*                'ClientScript.RegisterForEventValidation(r.UniqueID, "Select$" & columnIndex)
'            Next
'        End If
'    Next

'    MyBase.Render(writer)
'End Sub
4

0 に答える 0