下面是我用来选择每个单元格的代码。但是,当我选择该单元格时,我需要该单元格中的数据,即 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