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

Remove items on unchecking

1 Answer 66 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Needha
Top achievements
Rank 1
Needha asked on 05 Jun 2013, 08:21 AM
Hi guys,

There is a radcombobox and an asp checkbox in my page. On unchecking the asp checkbox, i want to remove all items from the radcombobox drop down. I tried using a javascript code and loop through all the items and access each one to delete, but it was not successful. I need a working javascript code.

Thanks,
Needha

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Jun 2013, 09:17 AM
Hi Needha,

To clear the items, you dont need to loop through and access individual items of the RadComboBox. The clearItems() client method can be used to remove all the items in the RadComboBox. Please have a look at the following code I tried which works as expected.

ASPX:
<asp:CheckBox ID="CheckBox1" runat="server" Text="Clear Items" onclick="clearItems(this);" />
<telerik:RadComboBox ID="RadComboBox1" runat="server" EmptyMessage="Select Item">
    <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>

JavaScript:
<script type="text/javascript">
    function clearItems(sender) {
        var RadComboBox1 = $find('<%=RadComboBox1.ClientID %>');
        RadComboBox1.clearItems();
    }
</script>

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