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

Add item for Rad combo box in client side problem

1 Answer 768 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Prasanna
Top achievements
Rank 1
Prasanna asked on 05 Mar 2013, 03:05 PM
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


1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 08 Mar 2013, 03:43 PM
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.
Tags
ComboBox
Asked by
Prasanna
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or