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

How do you programmatically clear selected values?

4 Answers 1009 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Veteran
Iron
Rob asked on 08 Jul 2020, 07:48 PM
I thought I could do it with "[control_name].items.clear()" but that doesn't seem to work either.

4 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
Veteran
Iron
answered on 09 Jul 2020, 02:24 PM
I'm able to clear the control's selection by setting [control_name].Value = null (or string.empty) but you then have to check for that condition when gathering the values when submitting the form. I just thought there would be built-in way to clear the field.
0
Accepted
Attila Antal
Telerik team
answered on 13 Jul 2020, 09:12 AM

Hi Rob,

The Items collection of RadMultiSelect is the dropdown element holding the list of items you can select from and by clicking on an item the input element will be populated with a value. Having that said, clearing the MultiSelect can be done by clearing the Input value as you have done by setting it to a null or empty string.

You may also try to assign an empty object array to it like in the example below:

<telerik:RadMultiSelect runat="server" DataValueField="text" Filter="Contains" EnforceMinLength="false" Placeholder="Select attendees..."
    DataTextField="text" Width="500px" ID="RadMultiSelect1">
    <Items>
        <telerik:MultiSelectItem Text="Steven White"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Nancy King"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Nancy Davolio"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Robert Davolio"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Michael Leverling"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Andrew Callahan"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Michael Suyama"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Anne King"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Laura Peacock"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Robert Fuller"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Janet White"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Nancy Leverling"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Robert Buchanan"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Margaret Buchanan"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Andrew Fuller"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Anne Davolio"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Andrew Suyama"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Nige Buchanan"></telerik:MultiSelectItem>
        <telerik:MultiSelectItem Text="Laura Fuller"></telerik:MultiSelectItem>
    </Items>
</telerik:RadMultiSelect>

<telerik:RadButton ID="RadButton1" runat="server" Text="Simple PostBack"></telerik:RadButton>
<telerik:RadButton runat="server" ID="RadButton2" Text="Clear Selected Values" OnClick="RadButton2_Click" />

<script runat="server">
    protected void RadButton2_Click(object sender, EventArgs e)
    {
        RadMultiSelect1.Value = new object[] { };
    }
</script>

 

Controls, in general, do not implement the Clear items/value functionality, instead, they all provide the API methods/functions that can be used to do that. Nevertheless, we are open to new ideas, and if you have some, please feel free to share it in the Progress® Telerik® UI for ASP.NET AJAX Feedback Portal. Public ideas that get popular will have the potential to get implemented in our source code.

Please let me know if you have further questions.

Kind regards,
Attila Antal
Progress Telerik

0
Hugo Augusto
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 03 Feb 2021, 07:20 PM

Hello,

just want to correct you when you say controls  do not implement the Clear items functionality. 

in RadDropDownTree you have control.Entries.Clear() + control.EmbeddedTree.UncheckAllNodes();

In RadTreeView you have control.Nodes.Clear();

In RadDateTimePicker you have control.Clear();

So it would make total sense to have a control.Clear(); in RadMultiSelect since you have provided an easy way to do it in other controls.

Regards,

Hugo Augusto

0
Attila Antal
Telerik team
answered on 03 Feb 2021, 11:24 PM

Hi Hugo,

I apologize if I have confused you with my message.

By the statement "Controls, in general, do not implement the Clear items/value functionality" I mean that the Clear functionality is not a built-in ability you would see as a Button in the Control or an X icon, or similar to those.

For the part "instead, they all provide the API methods/functions that can be used to do that." I mean API methods/functions similar to those you have listed:

  • in RadDropDownTree you have control.Entries.Clear() + control.EmbeddedTree.UncheckAllNodes();
  • In RadTreeView you have control.Nodes.Clear();
  • In RadDateTimePicker you have control.Clear();
  • So it would make total sense to have a control.Clear();

 

Regards,
Attila Antal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
MultiSelect
Asked by
Rob
Top achievements
Rank 1
Veteran
Iron
Answers by
Rob
Top achievements
Rank 1
Veteran
Iron
Attila Antal
Telerik team
Hugo Augusto
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or