Remove items on unchecking

2 posts, 0 answers
  1. Needha
    Needha avatar
    14 posts
    Member since:
    Mar 2013

    Posted 05 Jun 2013 Link to this post

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

    Posted 05 Jun 2013 Link to this post

    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.
Back to Top