Hi everyone,
I am pretty new to the whole salami and I have seen some posts about the subject, but I dont get it. If you click somewhere in a grid (in one of the cells), i want to know what is the columns uniquename this cell belongs to. I am coding in vb.net.
Ciao Peter.
4 Answers, 1 is accepted
0
Accepted
Shinu
Top achievements
Rank 2
answered on 10 Mar 2010, 06:56 AM
Hello Peter,
One sugestion would be attaching OnClick event for each cell and pass the ColumnUniqueName as a parameter to client side handler. Then save the ColumnUniqueName in a hiddenfield if you want to access from code behind.
VB:
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) |
For Each item As GridDataItem In RadGrid1.MasterTableView.Items |
For Each column As GridColumn In RadGrid1.MasterTableView.Columns |
item(column.UniqueName).Attributes.Add("onclick", "getColumnCliecked('" & column.UniqueName & "');") |
Next |
Next |
End Sub |
JavaScript:
function getColumnCliecked(un) { |
alert(un); |
// Save the un in a HiddenField if want to access from server side |
} |
-Shinu.
0
peter
Top achievements
Rank 1
answered on 10 Mar 2010, 10:34 AM
Thanks for the reply.
Question: where do i put that javascript-thingie and how?
This is by the way some code i have to get the ApartmentID of a clicked cell (stored in a session variable).
Session("sesApartmentID") = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ApartmentID")
Would it be possible to get the columnname in a simalar fashion?
0
peter
Top achievements
Rank 1
answered on 10 Mar 2010, 10:58 AM
Hang on, i am getting it.... I wil be back.
0
peter
Top achievements
Rank 1
answered on 10 Mar 2010, 11:13 AM
Yes i understand.
So, add an event to every cell in the grid. Do so by looping through the grid and add the event. The even will read (in this case) the headertext (or any property from the column).
This code goes in the codebehind page of the aspx-page (VB.NET)
Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender
For Each item As GridDataItem In RadGrid1.MasterTableView.Items
For Each column As GridColumn In RadGrid1.MasterTableView.Columns
item(column.UniqueName).Attributes.Add("onclick", "getColumnCliecked('" & column.HeaderText & "');")
Next
Next
End Sub
So, some client side javascript in my aspx-page and done
<script language="javascript">
function getColumnCliecked(un) {alert(un);}
</script>
Thanks a lot.