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

ComboBox with dynamically added items strange behavior

1 Answer 15 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 21 Aug 2013, 11:20 AM
Hi!

I'm populating RadComboBox  (CheckBoxes = true) with items in Javascript:

combo.trackChanges();
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(subType.Text);
comboItem.set_value(subType.Id);
                                 
combo.get_items().add(comboItem);
combo.commitChanges();

But when I'm selecting those items, they're not appearing in the combobox as selected (see attached screenshot).
If I'm adding items on the server, everything works well. 
How do I add those items to get everything working as it should?

Thank you

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 21 Aug 2013, 12:01 PM
Hi Dmitry,

Please have a look at the full code I tried which works fine at my end.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true">
    <Items>
        <telerik:RadComboBoxItem runat="server" Text="Item 1" />
        <telerik:RadComboBoxItem runat="server" Text="Item 2" />
        <telerik:RadComboBoxItem runat="server" Text="Item 3" />
    </Items>
</telerik:RadComboBox>
<br />
<telerik:RadButton ID="RadButton1" runat="server" Text="Add" AutoPostBack="false"
    OnClientClicked="addItem">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function addItem(sender, args) {
        var combo = $find('<%=RadComboBox1.ClientID %>');
        combo.trackChanges();
        var comboItem = new Telerik.Web.UI.RadComboBoxItem();
        comboItem.set_text("SampleItem");
        comboItem.set_value("1");
        combo.get_items().add(comboItem);
        combo.commitChanges();
    }
</script>

Thanks,
Shinu.
Tags
ComboBox
Asked by
Dmitry
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Share this question
or