Insert items to destination listbox - serverside

6 posts, 0 answers
  1. ARJUN
    ARJUN avatar
    4 posts
    Member since:
    Jul 2014

    Posted 14 Jul 2014 Link to this post

    Hi,

    I'm trying to insert items to destination listbox to desired index. If any item is selected in the destination lisbox then the transfered items should be inserted above the selected item. I'm using allowtransfer property for transferring the items.

    In transferring event i used "e.Cancel" to cancel the regular transfer when there is any item selected in the destination listbox. 

    e.Cancel = True

    For Each item As RadListBoxItem In e.Items
         e.DestinationListBox.Items.Insert(e.DestinationListBox.SelectedIndex, item)
    Next

    Insert doesn't work. What am I doing wrong? It doesn't give any error but doesn't work either. I have other functionality for which I have to make this happen through code behind itself.

    Thanks,
    Arjun
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Jul 2014 in reply to ARJUN Link to this post

    Hi ARJUN,

    Please have a look into the sample code snippet which works fine at my end. Please provide your full code if it doesn't help.

    ASPX:
    <telerik:RadListBox ID="rlstboxSourceList" runat="server" AutoPostBackOnTransfer="true" SelectionMode="Multiple" AllowTransfer="true" TransferToID="rlstboxDestinationList" OnTransferring="rlstboxSourceList_Transferring1">
        <Items>
            <telerik:RadListBoxItem Text="Item1" />
            <telerik:RadListBoxItem Text="Item2" />
            <telerik:RadListBoxItem Text="Item3" />
            <telerik:RadListBoxItem Text="Item4" />
            <telerik:RadListBoxItem Text="Item5" />
            <telerik:RadListBoxItem Text="Item6" />
        </Items>
    </telerik:RadListBox>
    <telerik:RadListBox ID="rlstboxDestinationList" runat="server" SelectionMode="Multiple">
        <Items>
            <telerik:RadListBoxItem Text="Item7" />
            <telerik:RadListBoxItem Text="Item8" />
        </Items>
    </telerik:RadListBox>

    VB:
    Protected Sub rlstboxSourceList_Transferring1(sender As Object, e As Telerik.Web.UI.RadListBoxTransferringEventArgs)
        Dim index As Integer
        For Each item As RadListBoxItem In e.Items
            index = e.DestinationListBox.SelectedIndex
            rlstboxDestinationList.Items.Insert(index, item)
        Next
    End Sub

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ARJUN
    ARJUN avatar
    4 posts
    Member since:
    Jul 2014

    Posted 15 Jul 2014 Link to this post

    Hi Shinu,

    Thanks for your response. The code which you posted works fine but that's the exact same thing what i have at my side too. I think I'm missing something. Below is my code.

    <telerik:RadListBox ID="RadListBox_Left" Height="300px" Width="300px" runat="server"
             AllowTransfer="true" TransferMode="Move" TransferToID="RadListBox_Right" Sort="Ascending"
             SelectionMode="Multiple" AllowTransferOnDoubleClick="false" AutoPostBackOnTransfer="true" >
    </telerik:RadListBox>

    <telerik:RadListBox ID="RadListBox_Right" Height="300px" Width="300px" runat="server" 
             AllowReorder="true">
    </telerik:RadListBox>

    Protected Sub RadListBox_Left_Transferring(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListBoxTransferringEventArgs) Handles RadListBox_Left.Transferring
            If e.DestinationListBox.ID = "RadListBox_Right" Then
                If e.DestinationListBox.SelectedIndex > -1 Then
                     For Each item As RadListBoxItem In e.Items
                           RadListBox_Right.Items.Insert(e.DestinationListBox.SelectedIndex, item)
                    Next
                End If
            End If
        End Sub

    Thanks,
    Arjun
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Jul 2014 in reply to ARJUN Link to this post

    Hi ARJUN,

    From your code I have noticed you are not setting SelectionMode as Multiple for the Source RadListBox. Please do the following modification in your code which works fine at my end.

    ASPX:
    <telerik:RadListBox ID="rlstboxDestinationList" runat="server" AllowReorder="true"
        SelectionMode="Multiple">
    </telerik:RadListBox>

    Thanks,
    Shinu.
  6. ARJUN
    ARJUN avatar
    4 posts
    Member since:
    Jul 2014

    Posted 16 Jul 2014 Link to this post

    Hi Shinu,

    Thanks. That works fine now. 

    Is there a way to get this working without the multiple selection for destination.....???? I cannot use multiple selection in destination listbox due to my application scenario. Not using multiple selection is a major thing for my application. 

    Can you suggest work around for this.

    Thanks,
    Arjun
  7. ARJUN
    ARJUN avatar
    4 posts
    Member since:
    Jul 2014

    Posted 16 Jul 2014 Link to this post

    Shinu,

    It's the multiple selection which is not letting the insert work. 

    For Each item As RadListBoxItem In e.Items
          RadListBox_Right.Items.Insert(index, item)
          RadListBox_Right.Items(index).Selected = False
    Next

    The above code lets any number of items to be inserted to destination. 

    This solves my issue. 

    Thanks,
    Arjun
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017