digitalZo
asked on
GridView specific Column click event
I had posted a question on gridview cell click here: https://www.experts-exchange.com/questions/22880624/GridView-cell-click-event.html
I got my answer and now what I want to know - Is there any way where we can limit the cell click to only ONE particular column - say only the first column. I do not want any click event to happen anywhere on the grid except the first column. Can anyone help?
This is the code [from that link]:
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewRo wEventArgs ) Handles GridView1.RowCreated
Dim gr As GridViewRow
For Each gr In GridView1.Rows
Dim tc As TableCell
For Each tc In gr.Cells
tc.Attributes.Add("onclick ", "alert('This is ID" & tc.Text & "')")
Next tc
Next gr
End Sub
I got my answer and now what I want to know - Is there any way where we can limit the cell click to only ONE particular column - say only the first column. I do not want any click event to happen anywhere on the grid except the first column. Can anyone help?
This is the code [from that link]:
Protected Sub GridView1_RowCreated(ByVal
Dim gr As GridViewRow
For Each gr In GridView1.Rows
Dim tc As TableCell
For Each tc In gr.Cells
tc.Attributes.Add("onclick
Next tc
Next gr
End Sub
ASKER
It's throwing an error: Property access must assign to the property or use its value.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
But 'tc.Text' is not declared because in the original code it is defined as 'Dim tc As TableCell'. How would I get the value of the cell?
ASKER
Okay thanks I got it. I tried it this way:
For Each gr In GridView1.Rows
gr.Cells(0).Attributes.Add ("onclick" , "alert('This is ID" & gr.Cells(0).Text & "')")
Next gr
For Each gr In GridView1.Rows
gr.Cells(0).Attributes.Add
Next gr
missed that...
replace tc.Text with
gr.Cells(0).Text
actually...
the tc from your original code is now replaced with
gr.Cells(0)
meaning the first cell in the row
replace tc.Text with
gr.Cells(0).Text
actually...
the tc from your original code is now replaced with
gr.Cells(0)
meaning the first cell in the row
ASKER
Just another random question: What if I want to limit the click event to selected columns?
Protected Sub GridView1_RowCreated(ByVal
Dim gr As GridViewRow
For Each gr In GridView1.Rows
gr.Cells[0].Attributes.Add
Next gr
End Sub