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

How to clear text in DropDownList

2 Answers 789 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 09 Aug 2013, 08:04 PM

Since I don't require all the functionality of the RadComboBox, I'm migrating several of my RadComboBox
controls over to the new RadDropDownList...but I'm having issues clearing the "text" portion of the
control via client-side script.

When using ComboBox, my client-side script to clear the control was,

resultsComboBox.trackChanges();
resultsComboBox.clearSelection();
resultsComboBox.clearItems();
resultsComboBox.commitChanges();

Now that I'm using DropDownList, my client-side script is,

resultsDropDownList.trackChanges();
resultsDropDownList.get_items().clear();
resultsDropDownList.commitChanges();

This clears the DropDownListCollection fine, but leaves the "selected" item in the top-level box.

Is there a DropDownList equivalent for the ComboBox clearSelection() client-side method?  I've tried setting the default message via
set_defaultMessage("xx") method...but no luck.  Any suggestions?  Thanks.

2 Answers, 1 is accepted

Sort by
0
A2H
Top achievements
Rank 1
answered on 10 Aug 2013, 04:47 AM
Hello,

Please try the below implementation
<script type="text/javascript">
       function ClearItems() {
           var $ = $telerik.$;
          var resultsDropDownList= $find("<%=RadDropDownList1.ClientID %>");
          resultsDropDownList.trackChanges();
          //To Clear the Selected Item
          if (resultsDropDownList.get_selectedItem()) {
              resultsDropDownList.get_selectedItem().set_selected(false);
          }
          resultsDropDownList.get_textElement().innerHTML = "";
          resultsDropDownList.get_items().clear();
           //To Clear the Default Message
           resultsDropDownList.set_defaultMessage(" ");
           resultsDropDownList.commitChanges();
       }
   </script>


Thanks,
A2H
0
David
Top achievements
Rank 1
answered on 13 Aug 2013, 04:36 PM
tt
Works great!  Thanks A2H!
Tags
DropDownList
Asked by
David
Top achievements
Rank 1
Answers by
A2H
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or