This is a migrated thread and some comments may be shown as answers.

GetDataKeyValues returns null

3 Answers 193 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
JFB
Top achievements
Rank 1
JFB asked on 05 Mar 2012, 04:24 PM
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 ?

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Mar 2012, 05:44 AM
Hello,

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.
C#:
foreach (TreeListDataItem item in RadTreeList1.Items)
{
   string xItemsId = Convert.ToString(item.GetDataKeyValue("xItemsId"));
}

-Shinu.
0
JFB
Top achievements
Rank 1
answered on 06 Mar 2012, 03:22 PM
I have tried this option before and got this exception: KeyNames collection length must match ParentKeyNames collection length.
0
Tsvetina
Telerik team
answered on 08 Mar 2012, 09:59 AM
Hi,

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,
Tsvetina
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.
Tags
TreeList
Asked by
JFB
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
JFB
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or