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

Selected Items, Client

3 Answers 169 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
pedrotti
Top achievements
Rank 1
pedrotti asked on 23 Jan 2013, 03:44 PM
Hello

Can you tell me you to loop on selectedItems

 var listbox = $find("<%= lbEssenceDispo.ClientID %>");
 var items = listbox.get_selectedItems();

I've not found how to do

Thank a lot

Anne

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Jan 2013, 04:10 AM
Hi,

Try the following code snippet to achieve your scenario.

JS:
<script type="text/javascript">
    function OnClientClick() {
        var listbox = $find("<%= lbEssenceDispo.ClientID %>");
        var items = listbox.get_selectedItems();
        for (var i = 0; i < items.length; i++) {
            //get the selected items here
            var selecteditem = items[i];
        }
    }
</script>

Hope this helps.

Regards,
Princy.
0
pedrotti
Top achievements
Rank 1
answered on 24 Jan 2013, 07:19 AM
Hi Princy and thank you !

I've try this but "items.length" allways return 0
Another idea ?

Have a good day

Anne
0
Princy
Top achievements
Rank 2
answered on 25 Jan 2013, 05:23 AM
Hi,

I was not able the replicate the issue that you are facing. Following is the complete code which worked as expected at my end.

ASPX:
<telerik:RadListBox ID="lbEssenceDispo" runat="server" SelectionMode="Multiple">
    <Items>
        <telerik:RadListBoxItem Text="RadListBoxItem1" />
        <telerik:RadListBoxItem Text="RadListBoxItem2" />
        <telerik:RadListBoxItem Text="RadListBoxItem3" />
        <telerik:RadListBoxItem Text="RadListBoxItem4" />
        <telerik:RadListBoxItem Text="RadListBoxItem5" />
        <telerik:RadListBoxItem Text="RadListBoxItem6" />
        <telerik:RadListBoxItem Text="RadListBoxItem7" />
        <telerik:RadListBoxItem Text="RadListBoxItem8" />
        <telerik:RadListBoxItem Text="RadListBoxItem9" />
    </Items>
</telerik:RadListBox>
<asp:Button ID="Button1" runat="server" OnClientClick="OnClientClick(); return false;" />

JS:
<script type="text/javascript">
    function OnClientClick() {
        var listbox = $find("<%= lbEssenceDispo.ClientID %>");
        var items = listbox.get_selectedItems();
        for (var i = 0; i < items.length; i++) {
            //get the selected items here
            var selecteditem = items[i];
            alert(selecteditem.get_text());
        }
    }
</script>

Please provide your entire code if it doesn't help.

Regards,
Princy.
Tags
ListBox
Asked by
pedrotti
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
pedrotti
Top achievements
Rank 1
Share this question
or