<
telerik:RadGrid
ID
=
"GridView1"
OnDataBound
=
"GridView1_DataBound"
runat
=
"server"
DataSourceID
=
"SqlDataSourceKategori"
AutoGenerateColumns
=
"False"
Skin
=
"Windows7"
>
<
MasterTableView
DataSourceID
=
"SqlDataSourceKategori"
DataKeyNames
=
"ID"
>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"Kategori"
>
<
EditItemTemplate
>
but i couldnt get datakeyname value at codebehind
i tried beloow
Label16.Text = GridView1.MasterTableView.DataKeyValues[0].ToString();
"System.Collections.Hashtable+ValueCollection"
please help me
5 Answers, 1 is accepted
Use the "GetDataKeyValue" method to get the keyvalue of GridDataItem.
Code:
Label16.Text = GridView1.MasterTableView.Items[0].GetDataKeyValue(
"ID"
).ToString();
Have a great day... :)
Regards,
Princy.
Protected
Sub
RadGrid1_SelectedIndexChanged(sender
As
Object
, e
As
System.EventArgs)
Handles
RadGrid1.SelectedIndexChanged
Label1.Text = gvRegion.SelectedValue.ToString
End
Sub
Oops, the line should read:
Label1.text = RadGrid1.SelectedValue.ToString
(Sorry 'bout that, chief)
Hi Sean,
Thank you for sharing this solution!
I would like to note that this approach is suitable for scenarios with single row selection (AllowMultiRowSelection="false") and also when there is only one filed set in the DataKeyNames property of the RadGrid.
In cases with disabled RowSelection, enabled MultiRowSelection or multiple DataKeyNames, using the GetDataKeyValue method is recommended, see Accessing Raw Field Data and Key Values
Kind regards,
Doncho
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.