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

Clear button on RadCombBox

5 Answers 407 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 28 Aug 2019, 12:16 PM

 

Is there a way to clear a multi check rad combo box without postback or is there a clear button already built into the control? 

Alex

5 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 30 Aug 2019, 03:05 PM

Hi Alex,

Thank you for your question!

Here is a sample which you can use:

 

<script type="text/javascript">
    function Uncheck() {
        var combo = $find("<%=RadComboBox1.ClientID %>");
        var items = combo.get_checkedItems();

        var i = 0;
        while (i < items.length) {
            items[i].uncheck();
            i++;
        }
    }
</script>
<telerik:RadComboBox ID="RadComboBox1" runat="server" EmptyMessage="check items"
    CheckBoxes="true" EnableCheckAllItemsCheckBox="true">
    <Items>
        <telerik:RadComboBoxItem Text="item 1" Value="1" />
        <telerik:RadComboBoxItem Text="item 2" Value="2" />
        <telerik:RadComboBoxItem Text="item 3" Value="3" />
        <telerik:RadComboBoxItem Text="item 4" Value="4" />
    </Items>
</telerik:RadComboBox>
<asp:Button ID="Button1" runat="server" OnClientClick="Uncheck()" Text="Uncheck" />

You can find more details at How to reset RadComboBox with Checkboxes using Javascript.

Please try the solution and share your feedback with me.

Best Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alex
Top achievements
Rank 1
answered on 04 Sep 2019, 02:52 PM

Hi Rumen

I have try this but it still posting back. 

The clear button is within the combo box (see the code below) , could this be causing a problem with the post back? 

 function ClearElementType() {
           var combo = $find("<%=rcmbElementType.ClientID %>");
           var items = combo.get_checkedItems();

           var i = 0;
           while (i < items.length) {
               items[i].uncheck();
               i++;
           }
        }

<telerik:RadComboBox ID="rcmbElementType" runat="server" Skin="Bootstrap" Width="280px" DataSourceID="sdsElementType" DataValueField="ElementType" DataTextField="ElementType"  EmptyMessage="Select a Element Type" OnItemDataBound="rcmbElementType_ItemDataBound" CheckBoxes="true"   >
                                                         <HeaderTemplate> 
                                                              <asp:Button ID="lnkClearCombBox" runat="server" Text="Clear"   OnClientClick="ClearElementType()" UseSubmitBehavior="false" AutoPostBack="false"/>
                                                        </HeaderTemplate>
                                                    </telerik:RadComboBox>

Alex

0
Rumen
Telerik team
answered on 05 Sep 2019, 02:44 PM
Hi Alex,

Set return false after the function call to cancel the postback:

<script>
    function ClearElementType() {
        var combo = $find("<%=rcmbElementType.ClientID %>");
        var items = combo.get_checkedItems();
 
        var i = 0;
        while (i < items.length) {
            items[i].uncheck();
            i++;
        }
        return false;
    }
</script>
<telerik:RadComboBox ID="rcmbElementType" runat="server" Skin="Bootstrap" Width="280px" EmptyMessage="Select a Element Type" CheckBoxes="true">
    <HeaderTemplate>
        <asp:Button ID="lnkClearCombBox" runat="server" Text="Clear" OnClientClick="ClearElementType();return false" UseSubmitBehavior="false" AutoPostBack="false" />
    </HeaderTemplate>
    <Items>
        <telerik:RadComboBoxItem Text="item 1" Value="1" />
        <telerik:RadComboBoxItem Text="item 2" Value="2" />
        <telerik:RadComboBoxItem Text="item 3" Value="3" />
        <telerik:RadComboBoxItem Text="item 4" Value="4" />
    </Items>
</telerik:RadComboBox>


Regards,
Rumen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alex
Top achievements
Rank 1
answered on 05 Sep 2019, 03:06 PM

Hi Rumen 

 

That has worked

Thanks

Alex

0
Rumen
Telerik team
answered on 05 Sep 2019, 03:20 PM
You are welcome, Alex! Keep up the good work.

Regards,
Rumen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Alex
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Alex
Top achievements
Rank 1
Share this question
or