This is a migrated thread and some comments may be shown as answers.

with multiple select the selecteditem is not updated

3 Answers 104 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Hubert
Top achievements
Rank 1
Hubert asked on 15 Aug 2012, 11:51 AM
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

3 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 16 Aug 2012, 08:14 AM
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.
0
Hubert
Top achievements
Rank 1
answered on 18 Aug 2012, 12:25 PM
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
0
Nencho
Telerik team
answered on 20 Aug 2012, 07:36 AM
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.
Tags
ListBox
Asked by
Hubert
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Hubert
Top achievements
Rank 1
Share this question
or