with multiple select the selecteditem is not updated

4 posts, 0 answers
  1. Hubert
    Hubert avatar
    19 posts
    Member since:
    Feb 2012

    Posted 15 Aug 2012 Link to this post

    Hi,

    when you click Barcelona in the left ListBox of the telerik demos - ListBox - server side events
    the event SelectedIndexChanged is fired and in the Properties RadListBox1.SelectedIndex
    and RadListBox1.SelectedValue
    are the actual values.

    But in "multiple select" scenario the SelectedIndex and SelectedValue do not change (sometimes).
    Hold CTRL and select Bonn and Boston. You can see that the server event is fired, but the text is still Barcelona
    and the index does not change.

    Sometimes the correct values are fired, but not with every click holding the CTRL key down to select multiple values.

    cheers
    Hubert
  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 16 Aug 2012 Link to this post

    Hello Hubert,

    Let me explain in more details how the demo you have inspected works. With the SelectionMode set to "Multiple", each selected item is added to the SelectedItemsCollection at the SelectedIndexChanged event handler. This collection is arranged in an ascending order in regards to the index of each item. In the demo, we show the selected value and index only of the first item of the aforementioned collection ( the one with the lower index ).
    Therefore,  you could observe the SelectedIndex changed in the EventLog only when you select an item that is just above the previously selected one.

    Greetings,
    Nencho
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hubert
    Hubert avatar
    19 posts
    Member since:
    Feb 2012

    Posted 18 Aug 2012 Link to this post

    Hello Nencho,

    i can confirm the behavior, but how is it possible to get the last selected item, when multiple selection
    is activated?

    Greetings,
    Hubert
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 20 Aug 2012 Link to this post

    Hi Hubert,

    You could use the OnClientSelectedIndexChanged client event , in order to easily access the last selected item. Please consider the following approach :

    <div>
           <telerik:RadListBox ID="RadListBox1" runat="server" Width="256px" Height="320" AutoPostBack="true"
               OnClientSelectedIndexChanged="onClientSelectedIndexChanged" SelectionMode="Multiple">
               <Items>
                   <telerik:RadListBoxItem runat="server" Text="item1" />
                   <telerik:RadListBoxItem runat="server" Text="item2" />
                   <telerik:RadListBoxItem runat="server" Text="item3" />
                   <telerik:RadListBoxItem runat="server" Text="item4" />
                   <telerik:RadListBoxItem runat="server" Text="item5" />
               </Items>
           </telerik:RadListBox>
       </div>
       <script type="text/javascript">
     
           function onClientSelectedIndexChanged(sender, args) {
     
               alert(args.get_item().get_text())
           }
       
       </script>



    Regards,
    Nencho
    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.
Back to Top