Frage

I may be missing something trivial, so bear with me here.

I've two RadListBox, a source and a destination.

<telerik:RadListBox runat="server" ID="rdlbDisplayColumnsSource" AllowTransfer="true"
TransferMode="Move" TransferToID="rdlbDisplayColumnsDest" CssClass="rdlbDisplayColumns">
    <Items></Items>
</telerik:RadListBox>
<telerik:RadListBox runat="server" ID="rdlbDisplayColumnsDest" CssClass="rdlbDisplayColumns"
AllowReorder="true">
    <Items></Items>
</telerik:RadListBox>

The user selects the fields to be moved from Source to Destination and when the user saves the form, the selected item's values are persisted into DB. The next time the user loads the form, the selection needs to be shown. For doing so I wrote the following code to transfer the items from the source to destination in the backend.

var displayCols = _Model.AdditionalDisplayColumns.Split(',');
foreach (var val in displayCols)
{
    var item = rdlbDisplayColumnsSource.FindItemByValue(val);
    rdlbDisplayColumnsSource.Transfer(item, rdlbDisplayColumnsSource, rdlbDisplayColumnsDest);
}

I was expecting the items being transferred to be removed from Source ListBox since the TransferMode is set to Move but that wasn't the case. The destination ListBox got refreshed with the previously selected items but those items were still present in source!

If I try to delete the selected items in source ListBox after transfer, it throws an exception that item isn't present in the listbox.

What is a cleaner way of achieving a 'Move' behavior from code behind while invoking .Transfer()?

War es hilfreich?

Lösung

Apparently, Page_Load is too early for the items to be removed from the source (funny that the items do end up showing in destination though!).

Moved the code to Pre_Render and things worked. Not so trivial!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top