This is a migrated thread and some comments may be shown as answers.
How to find if a DataKeyName exists
1 Answer 17 Views
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 10 Oct 2018, 05:46 AM
I am building a radgrid programmatically. Can anyone tell  me how to find out if a particular DataKeyName exists in the grid - something like e.Item.OwnerTableView.DataKeyNames.Contains("OBJECTID"). Since this is a generic grid, I might not know if a datakey exists. When I try to use GetDataKeyValue I get a null reference exception because a datakey might not exist.

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 10 Oct 2018, 06:16 PM
Hi Terry,

If set, the DataKeyNames can be accessed in the RadGrid1.MasterTableView.DataKeyNames property (server-side) which returns an array of strings ( string[] ). Then you can check to see if it contains a particular value as suggested in the following StackOverFlow article: https://stackoverflow.com/a/2912507

I hope this will be helpful!

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Terry
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or