Restrict items reordering in RadListBox in c#

183 Views Asked by At

I have a RadListBox which has 11 items. And I need to have the first 7 items as static which means they shouldn't be reordered. I have written the below javascript and it works just fine.

The 8th item in listbox is still movable(up) and this shouldn't happen. I need to reorder the items only after 7th item till 11th item and only within themselves. Means out of 11 items, first 7 items order should be static and from 8 to 11 these fields can be reordered.

Can anyone suggest how this can be achieved?

HTML:

<telerik:RadListBox ID="RadListBox" runat="server" 
 AllowReorder="true  OnClientSelectedIndexChanging="RadListBox_Reordering"/> 

JS:

function RadListBox_Reordering(sender, eventArgs) {
        var value = eventArgs.get_item().get_value();
        if (value == "Item1" || value == "Item2" || value == "Item3" || value == "Item4" || value == "Item5" || value == "Item6" || value == "Item7") {
            eventArgs.set_cancel(true);
        }
    }
1

There are 1 best solutions below

2
On

You can use the OnClientDropping event, which is cancelable, to detect where the reordered item is landing.

function OnClientDroppingHandler(sender, eventArgs) {
    var index = args.get_destinationItem().get_index();

       if (index < 8) {
           alert('you may not drop on the first 7 items');
           args.set_cancel(true);
       }
 }

https://www.telerik.com/forums/how-to-disable-dragging-dropping-to-first-position