How to clear text in DropDownList

3 posts, 0 answers
  1. David
    David avatar
    16 posts
    Member since:
    Jan 2012

    Posted 09 Aug 2013 Link to this post


    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. A2H
    A2H avatar
    177 posts
    Member since:
    Mar 2010

    Posted 09 Aug 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David
    David avatar
    16 posts
    Member since:
    Jan 2012

    Posted 13 Aug 2013 Link to this post

    tt
    Works great!  Thanks A2H!
Back to Top