How can I retrieve the column name for the selected cell in Telerik RadGrid?
Id Name LastName Telephone
1 jo jol 098
2 mo mol 987
3 fo fol 394
4 do doo 234
5 me mee 245
//For example, when a cell is clicked on the grid, how can I get the column name? Retrieve (Id) when clicking on Cell 1, Retrieve (LastName) when clicking on Cell jol
This is the code I am using:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script>
function CellSelected(sender, args) {
// Using ColumnUniqueId to get data from the row
var row = sender.get_masterTableView().get_dataItems()[args._itemIndexHierarchical];
var id = row.get_cell("ID").innerHTML;
var Name = row.get_cell("Name").innerHTML;
var Contact = row.get_cell("Contact").innerHTML;
//Missing code here to determine if the clicked cell belongs to the ID column
// For example, if the selected cell belongs to the ID column
if (parseInt(id) == 3) {
alert("Name:-" + Name + ",Contact:-" + Contact);
}
}
</script>
</telerik:RadCodeBlock>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Contact" UniqueName="Contact" HeaderText="Contact">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Selecting CellSelectionMode="Column" />
<ClientEvents OnCellSelected="CellSelected" />
</ClientSettings>
</telerik:RadGrid>