How to find if a DataKeyName exists

2 posts, 0 answers
  1. Terry
    Terry avatar
    13 posts
    Member since:
    Oct 2012

    Posted 10 Oct 2018 Link to this post

    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.
  2. Attila Antal
    Admin
    Attila Antal avatar
    246 posts

    Posted 10 Oct 2018 Link to this post

    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.
Back to Top