Add item for Rad combo box in client side problem

2 posts, 0 answers
  1. Prasanna
    Prasanna avatar
    47 posts
    Member since:
    Oct 2012

    Posted 05 Mar 2013 Link to this post

    Hi,

    I have two rad combo box in my page. I have to add only combo1.checkeditems to combo2.

    I tried following code, I got get_parent() error.

    combo2.trackChanges();
    for(var item=0;combo1.get_checkedItems().length;item++){
    combo2.get_items().add(combo1.get_checkedItems()[item]);
    }
    combo2.commitChanges();

    Please let me know its possible .......

    Thanks,
    Prasanna


  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 08 Mar 2013 Link to this post

    Hi Prasanna,

    Yes, it is possible. I can suggest you to get the checked items from the first combo and assign text and value to a new item. Finally add this new item to RadComboBoxItems collection of the second RadComboBox in the following manner:
    <script type="text/javascript">
             function AddItems() {
                 var combo1 = $find('<%= RadComboBox1.ClientID%>');
                 var combo2 = $find('<%= RadComboBox2.ClientID%>');
     
                 combo2.trackChanges();
                 for (var i = 0; i < combo1.get_checkedItems().length; i++) {
                     var item = new Telerik.Web.UI.RadComboBoxItem();
     
                     item.set_text(combo1.get_checkedItems()[i].get_text());
                     item.set_value(combo1.get_checkedItems()[i].get_value());
     
                     combo2.get_items().add(item);
                 }
                 combo2.commitChanges();
             }
         </script>
    This should be wrapped by track and commit changes to persist changes over post backs.
    <telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true">
              <Items>
                  <telerik:RadComboBoxItem runat="server" Text="Item 1" Value="1" />
                  <telerik:RadComboBoxItem runat="server" Text="Item 2" Value="2" />
                  <telerik:RadComboBoxItem runat="server" Text="Item 3" Value="3" />
              </Items>
          </telerik:RadComboBox>
          <telerik:RadComboBox ID="RadComboBox2" runat="server"></telerik:RadComboBox>
          <input id="Button1" type="button" value="Add checked items" onclick="AddItems()" />

    Greetings,
    Hristo Valyavicharski
    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.
Back to Top