ComboBox with dynamically added items strange behavior

2 posts, 0 answers
  1. Dmitry
    Dmitry avatar
    1 posts
    Member since:
    Aug 2013

    Posted 21 Aug 2013 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Aug 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top