Telerik radlistbox datakey does not transfer

907 Views Asked by At

I have two Telerik radListBoxes (source and destination). Both are databound with their DataKeyField and DataTextField values set. The destination listbox may have some values in it from a prior session.

When I transfer an item from the source listbox to the destination listbox using the built in buttons, I can see the value (text) is transferred over, but the datakey for that item is null.

I'm new to these controls, and everything is working well, except for this.

<telerik:RadListBox runat="server" ID="rlAvailableTitles" Height="200px" Width="300px" ButtonSettings-AreaWidth="35px" 
    AllowTransfer="true" TransferToID="rlTitles" SelectionMode="Multiple" AppendDataBoundItems="true"
    AllowTransferOnDoubleClick="true" DataKeyField="TitleID" DataTextField="TitleName" CssClass="text-align: left;" AutoPostBackOnTransfer="true">
</telerik:RadListBox>
<telerik:RadListBox runat="server" ID="rlTitles" Height="200px" Width="300px" ButtonSettings-AreaWidth="35px"
    AllowTransfer="true" TransferToID="rlAvailableTitles" SelectionMode="Multiple" AppendDataBoundItems="true"
    AllowTransferOnDoubleClick="true" DataKeyField="TitleID" DataTextField="TitleName">
</telerik:RadListBox>

And after they click on 'save':

foreach (RadListBoxItem item in rlTitles.Items)
{
    string myTitleID = item.DataKey;
    // etc...
} 

What am I missing to get the datakey that is stored with the item in the source listbox?

2

There are 2 best solutions below

0
On BEST ANSWER

DataKey has no setter.

Use DataValueField instead.

0
On

I found the solution to this particular problem. I added DataValueField="TitleID" to the source radListBox in the aspx file. Then in my code behind, the value that I'm looking for in the destination radListBox is available in item.Value. Seems pretty straight forward in retrospect.