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

set index from java script

3 Answers 87 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Dominik
Top achievements
Rank 1
Dominik asked on 27 Apr 2012, 11:02 AM
Hello, I try from client side (java script) set index for RadListBox.

How can I use document.getElementById for finding and set index for RadListBox ?

regards,
Dominik Kolcio

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Apr 2012, 11:31 AM
Hi Dominik,

You can access the RadListBox using $find method and get the index as shown below.

JS:
<script type="text/javascript">
    function pageLoad()
    {
        var list = $find("<%= RadListBox1.ClientID %>");
        var items = list.get_items();
        list.trackChanges();
        var item = new Telerik.Web.UI.RadListBoxItem();
        item.set_text("New");
        item.set_value("Value");
        items.add(item);
        list.commitChanges();
        alert(item.get_index());
    }
</script>

Thanks,
Shinu.
0
Dominik
Top achievements
Rank 1
answered on 27 Apr 2012, 11:55 AM
Yes, I try this before.
When try to run app:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

But this problem I solved with RadScriptBlock.

but I still can't set index in RadListBox from java script :(
I don't need add any Items, because my RadListtBox is populated with data.

I need select item by index.
0
Dominik
Top achievements
Rank 1
answered on 27 Apr 2012, 12:10 PM
I solved the problem.

With clearSelection
getItem and select

thank you Shinu

Dominik
Tags
ListBox
Asked by
Dominik
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Dominik
Top achievements
Rank 1
Share this question
or