GetDataKeyValues returns null

4 posts, 1 answers
  1. JFB
    JFB avatar
    6 posts
    Member since:
    Oct 2012

    Posted 05 Mar 2012 Link to this post

    I am trying to get a client data key value in my rad tree list, but it always returns null:

    private List<xItems> GetTreeListChanges()
            List<xItems> xItems = new List<xItems>();
            foreach(TreeListDataItem rtlItem in rtlxItems.Items)
                string xItemsId = Convert.ToString(rtlItem.GetDataKeyValue("xItemsId"));

    Here is the markup code, where my data key is well defined:

    <telerik:RadTreeList ID="rtlxItems" runat="server" AllowMultiItemEdit="false"
            ParentDataKeyNames="ParentId" DataKeyNames="ChlidId" ClientDataKeyNames="xItemsId">

    What can I do to get the datakey for a TreeListDataItem ?
  2. Answer
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Mar 2012 Link to this post


    You can access ClientDataKeyNames from client side only. One suggestion is you can set the DataKeyNames as "xItemsId" and access it from server side as shown below.
    foreach (TreeListDataItem item in RadTreeList1.Items)
       string xItemsId = Convert.ToString(item.GetDataKeyValue("xItemsId"));

  3. DevCraft R3 2016 release webinar banner
  4. JFB
    JFB avatar
    6 posts
    Member since:
    Oct 2012

    Posted 06 Mar 2012 Link to this post

    I have tried this option before and got this exception: KeyNames collection length must match ParentKeyNames collection length.
  5. Tsvetina
    Tsvetina avatar
    1862 posts

    Posted 08 Mar 2012 Link to this post


    In general you could do one of the following:

    1) On ItemDataBound event, access the DataItem object of the treelist item and get the needed value from it (DataItem is available only during this event).

    2) Use the key value of the TreeListDataItem and query the DB with it to access the respective record and the xItemsId value.

    Due to the way RadTreeList is build the DataKeyNames collection cannot include any field, only the ones used to build the treelist hierarchy should be specified there.

    All the best,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top