Below is the code that I use to select each individual cell. However, when I do select that cell, I need the data in that cell, the rowIndex and columnIndex. Unfortunately after all the research and trying others code.. I'm stuck on how to obtain the columnIndex of a selected cell in my gridView.
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
This is also what I've tried
*I tried doing a buttonField with a commandName "ColumnClick" . Then using grdResults_RowCommand to try and get the rowIndex and columnIndex however I get the enableEventValidation error page. Even though I have a overrided render that looked like:
'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