Clear RadComboBox text

28 posts, 1 answers
  1. Moustafa
    Moustafa avatar
    70 posts
    Member since:
    Jul 2008

    Posted 09 Oct 2008 Link to this post

    Hi ..telerik

    I have a small problem in clearing the text in the RadComboBox .

    I tried the following

    • RadComboBox1.Text="";        //do nothing
    • RadComboBox1.ClearSelection();

    but nothing cleared.
     
    the only solution

    • RadComboBox1.Text=" "; //set the text to one space

    which can effect the logic of the code

    Is there any solution for this problem ??

    Note:

    1. I'm using rad controls for asp.net ajax
    2. the RadComboBox allow Custom  Text so user can type what need.
  2. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 09 Oct 2008 Link to this post

    Hey Moustafa,

    I just tried and the combo of:

    RadComboBox1.Text = null;
    RadComboBox1.ClearSelection();

    seems to do the trick.  No clue why "" wouldn't work, but would setting it to null work with the logic you are going for?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 10 Oct 2008 Link to this post

    Hello,

    Please find attached sample project which shows that the selected item of RadComboBox can be cleared like this:

    RadComboBox1.Text = "";  
    RadComboBox1.ClearSelection(); 

    Regards,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Moustafa
    Moustafa avatar
    70 posts
    Member since:
    Jul 2008

    Posted 11 Oct 2008 Link to this post

    yes thank you very much, this solve the problem

    RadComboBox1.Text = "";   //clear the custom text

    RadComboBox1.ClearSelection();    clear the selected items

  6. Kumar
    Kumar avatar
    6 posts
    Member since:
    May 2008

    Posted 12 Feb 2010 Link to this post

    Hi,

     

    RadComboBox1.Text = "";  

    RadComboBox1.ClearSelection(); 

    Above steps not working for me.

    I don't want AllowCustomText="true"

    If I changed AllowCustomText="true", above steps are working

    If I changed RadComboBox1.Text = 
    " " (Note Double space) it is working but EmptyMessage not displaying.

    Could you give me the solution for this?

  7. Kamen Bundev
    Admin
    Kamen Bundev avatar
    1532 posts

    Posted 16 Feb 2010 Link to this post

    Hi Kumar,

    The EmptyMessage is just a placeholder for the text in editable RadComboBoxes, it can't be used in an read-only RadComboBox. As a workaround you can create a dummy first item and have it selected on load. This way your users will be able to revert their selection by themselves if they need to.

    All the best,
    Kamen Bundev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Kumar
    Kumar avatar
    6 posts
    Member since:
    May 2008

    Posted 22 Feb 2010 Link to this post

    Hi Kamen,

    Here I am not using RadComboBox as a 'ReadOnly". It seems to be RadComboBox1.Text has some problems.

  9. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 25 Feb 2010 Link to this post

    Hi Kumar,

    Which version of the controls you're using?  I've tested this with our latest release and setting Text property to empty string like this:

    RadComboBox1.Text = "";
     clears the text and the EmptyMessage appears.

    Please send us your definition of the combobox.

    Regards,
    Yana
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. ALAN NEMARIC
    ALAN NEMARIC avatar
    5 posts
    Member since:
    Jun 2009

    Posted 07 Apr 2010 Link to this post

    I am using Radcombobx with LoadOnDemand Property enabled
    I am trying to clear the selected item with follwoing code

    [CODE]
    cmbTest.Text="";
    cmbTest.ClearSelection();
    [/CODE]

    but it is not working.
    How can i do that for Enable LoadOnDemand property.
    Thanks in advance
  11. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 12 Apr 2010 Link to this post

    Hello ALAN NEMARIC,

    Your approach looks correct – when you use the ClearSelection() method the selected RadComboBoxItem is cleared. Setting the Text property of RadComboBox to empty string in fact applies the EmptyMessage.

    Could you please provide me with more details about your implementation and send me a sample page that illustrates the issue?

    Thank you in advance.

    Kind regards,
    Kalina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  12. Hans van Rijnswoud
    Hans van Rijnswoud avatar
    72 posts
    Member since:
    Sep 2008

    Posted 24 Aug 2010 Link to this post

    Hi Kalina,

    I have the same problem than Alan.
    ClearSelection() and text="" don't work.
    Deed you found the solution for this problem?

    In advance thanks for your help.

    here is the definition of my RadComboBox:
    <telerik:RadComboBox runat="server" ID="ddl_ParentCustomer" Width="410px" Height="300px"
                                    EnableLoadOnDemand="true" HighlightTemplatedItems="true" EnableVirtualScrolling="true"
                                    OnItemsRequested="RadComboBoxCustomerOnItemsRequested" OnItemDataBound="RadComboBoxCustomerOnItemDataBound"
                                    EmptyMessage="-Selecteer-" AutoPostBack="true">
                                    <HeaderTemplate>
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tr>
                                                <td style="width: 220px;">
                                                    Bedrijfsnaam
                                                </td>
                                                <td style="width: 50px;">
                                                    Postcode
                                                </td>
                                                <td>
                                                    Stad
                                                </td>
                                            </tr>
                                        </table>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tr>
                                                <td style="width: 220px;">
                                                    <%# Eval("Name")%>
                                                </td>
                                                <td width="50px;">
                                                    <%# Eval("ZipCode")%>
                                                </td>
                                                <td>
                                                    <%# Eval("City")%>
                                                </td>
                                            </tr>
                                        </table>
                                    </ItemTemplate>
                                </telerik:RadComboBox>


  13. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 27 Aug 2010 Link to this post

    Hi Edwin Blom,

    By design RadComboBox items loaded via Load On Demand are not persisted on server.  That is why ClearSelection server-side method does not clear the selected item. However you can simply set the RadComboBox Text and SelectedValue properties to empty string.

    I used the definition of your RadComboBox and created a sample page for you – please find it attached.
    If the issue persists – could you please paste here a simplified working code that reproduces it and explain your implementation in more details?

    Thank you in advance.

    Regards,
    Kalina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Sébastien
    Sébastien avatar
    60 posts
    Member since:
    Aug 2008

    Posted 27 Jan 2011 Link to this post

    Personnaly, none of the exposed solutions are working.
    I have to get the first item of the RadComboBoxItemCollection and edit his Text and Value properties.
    Please note that my RadCombox contains a selected value made by insertion of a specifically created RadComboBoxItem (because of LoadOnDemand).

    <telerik:RadComboBox ID="RadComboBox1" runat="server" LoadingMessage="Loading..." Width="200px" MaxHeight="300px" EmptyMessage="Please write the first letter of the name" EnableEmbeddedSkins="false"
    EnableAutomaticLoadOnDemand="true" ItemsPerRequest="50" ShowMoreResultsBox="true" EnableVirtualScrolling="true" DataSourceID="SqlDataSource1" DataTextField="Full_Name" DataValueField="IdUser" AutoPostBack="True"></telerik:RadComboBox>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="..." SelectCommand="LIST_Users" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

    // Let's create a selected Item.
    RadComboBoxItem itemcol = new RadComboBoxItem();
    itemcol.Value = "12345";
    itemcol.Text = "Selected Item";
    RadComboBox1.Items.Add(itemcol);
    RadComboBox1.SelectedValue = itemcol.Value;
     
    // This solution does not work.
    if (RadComboBox1.Items != null)
    {
         RadComboBox1.Text = "";
         RadComboBox1.SelectedValue = "";
         RadComboBox1.ClearSelection();
         RadComboBox1.Items.Clear();
    }
     
    // This solution does work.
    if (RadComboBox1.Items != null)
    {
         RadComboBoxItem itemcolToChange = RadComboBox1.Items[0];
         itemcolToChange.Text = "";
         itemcolToChange.Value = "";
    }

    Cheers,

    S.F.
  15. Dennys
    Dennys avatar
    6 posts
    Member since:
    Nov 2010

    Posted 22 Feb 2011 Link to this post

    Same problem here. ClearSelection() does not really clear the selection and display the EmptyMessage. None of the solutions/workarounds shown here worked for me. Using 2010.3 Controls.
  16. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 28 Feb 2011 Link to this post

    Hello Dennys,

    Could you please explain your implementation in more details and paste here working code that represents it?
    Thank you in advance.

    Best wishes,
    Kalina
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  17. Matt DiPietro
    Matt DiPietro avatar
    23 posts
    Member since:
    Nov 2009

    Posted 11 Jul 2011 Link to this post

    I have this problem as well.  When I check at a breakpoint, SelectedIndex = -1, SelectedItem = nothing, Text = "", yet the combo box displays the text of the first item.  This is on initial page load too, so I shouldn't be needing to reset them as it is.
  18. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 14 Jul 2011 Link to this post

    Hello Matt Dipietro,

    When the RadComboBox control is read-only - there is always a selected item in it.
    Please try setting the AllowCustomText property to "true".

    Then if you prefer to restrict user typing in RadComboBox input you can make this by handling the OnClientLoad event of the control in this way:

    function onLoad(sender) {
        sender.get_inputDomElement().readOnly = "readonly";
    }


    All the best,
    Kalina
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  19. sameer
    sameer avatar
    2 posts
    Member since:
    Apr 2011

    Posted 18 Jul 2011 Link to this post

    I am using radcombobox Item template and by default first item is selected ! tried setting the as follows in the code behind;

    rcb.Text = null;
    rcb.ClearSelection();

    Not working...

    rcb.Text = "";
    rcb.ClearSelection();

    Not working

    rcb.DataBind();    //-- data source is entitydatasource
    rcb.Text = "";
    rcb.ClearSelection();

    Not working....

    Any update on this...

  20. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 18 Jul 2011 Link to this post

    Hello Sameer,

    As I have already explained in my previous post here:
    "When the RadComboBox control is read-only - there is always a selected item in it.
    Please try setting the AllowCustomText property to "true"
    .

    I hope this helps.

    All the best,
    Kalina
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  21. Edwin
    Edwin avatar
    6 posts
    Member since:
    Jul 2011

    Posted 19 Jul 2011 Link to this post

    I am getting that this object does not support this property when I added the  OnClientLoad="onLoad(this)"

    <telerik:RadComboBox ID="ddlMyTypes" EmptyMessage="All Types" runat="server" Width="200px" AllowCustomText="true" OnClientLoad="onLoad(this)">
                <ItemTemplate>
                 <div onclick="StopPropagation(event)">
                  <asp:CheckBox runat="server" ID="chk1" onclick="onCheckBoxClick(this)"/>
                                    <asp:Label runat="server" ID="lblProfile" AssociatedControlID="chk1">
                                       <%# Eval("Name") %>
                                    </asp:Label>
                 </div>
                </ItemTemplate>
                </telerik:RadComboBox>                
            </div>
    function onLoad(sender) {
                 sender.get_inputDomElement().readOnly = "readonly";
             }
  22. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Jul 2011 Link to this post

    Hello Edwin,

    The Ajax controls (all of our controls from the RadControls for ASP.NET Ajax suite) expect an object of type function for their client-side events.
    So on the OnClientLoad event you only need to give the function name.
    OnClientLoad="onLoad"

    Thanks,
    Shinu.
  23. Matt DiPietro
    Matt DiPietro avatar
    23 posts
    Member since:
    Nov 2009

    Posted 20 Sep 2011 Link to this post

    I'm still having problems with this.  I tried ClearSelection(), setting text = "", setting text = String.Empty--regardless of what I do, the value is blank, but the text visible on screen is the text of the first item in the list, not the EmptyMessage.

    This is a problem because when I try to save the record, it sees the text and stores that value instead of storing a blank string.  Why wouldn't ClearSelection() just set the text to an empty string?

    Previously I was told to allow custom text--the only problem is that I already AM allowing custom text!  What's the deal?
  24. Matt DiPietro
    Matt DiPietro avatar
    23 posts
    Member since:
    Nov 2009

    Posted 20 Sep 2011 Link to this post

    I finally got this fixed--I had to explicitly set the AllowCustomText = true for this to work the correct way.  I was confused because not explicitly setting that attribute still allowed custom text to be entered by the user and saved to the database.

    My question is now this:  if the default behavior is to allow users to enter custom text even if AllowCustomText isn't explicitly defined, why does it need to be defined for RadControlBox.ClearSelection() to work?  Once I set the attribute, I didn't even need to set Text="" when clearing values to achieve the desired behavior.
  25. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 23 Sep 2011 Link to this post

    Hi Matt,

    In case the AllowCustomText is explicitly set to True you are not able to enter custom text in the input of the RadComboBox. When using load on demand this property is set to True automatically since it's required.

    Regards,
    Dimitar Terziev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  26. Kanna
    Kanna avatar
    5 posts
    Member since:
    Aug 2010

    Posted 22 Dec 2011 Link to this post

    Hello Everyone, 
    Finally fixed this problem.
    I'm using the telerik radControls for ajax version 2011.2.915.40.
    Really, no solution specified in this thread is worked for me.
    My RadCombo have the property AllowCustomText="true" and EnableLoadOnDemand="True" as shown below.

     <telerik:RadComboBox ID="rcbEmployee" runat="server" Width="450px" Height="150px" AllowCustomText="true"
                                        Filter="Contains" EnableLoadOnDemand="True" DataTextField="EmployeeName" DataValueField="EmployeeKey"
                                        ShowMoreResultsBox="true" ItemRequestTimeout="1000" EnableVirtualScrolling="true"
                                        OnSelectedIndexChanged="rcbEmployee_SelectedIndexChanged" OnItemsRequested="rcbEmployee_ItemsRequested"
                                        Localization-AllItemsCheckedString="">



    Finally below solution is worked well for me for clearing.
     rcbEmployee.Text = "";
     rcbEmployee.SelectedValue = "";

     rcbEmployee.ClearSelection();
     //Above lines will clear the selection and displays Empty Message but still the item exists in the list.
     rcbEmployee.Items.Clear(); //That's y clearing the entire list here.
     rcbEmployee.DataBind(); //Binding again

    It might be helpful for anyone. If it is not the perfect way, can anyone share their solutions.

    Thanks,
    Santhosh Kumar G
  27. TonyG
    TonyG avatar
    239 posts
    Member since:
    Feb 2006

    Posted 30 Apr 2012 Link to this post

    I just came to the forum with this problem too. It seems like over-kill, but Kumar's solution is the best for my purposes. Thanks Kumar.

    When I clean up my current project I'll probably create a helper method just to reduce some of this in-line housekeeping (a derived class seems like even more overkill ;)  :

     

    lstAccounts.Text = ""// clear current combo before loading
    lstAccounts.SelectedValue = ""
    lstAccounts.ClearSelection(); 
    lstAccounts.Items.Clear(); 
    lstAccounts.DataSource = accounts; 
    lstAccounts.DataBind(); 
    lstVessels.Text = ""; // this combo is dependent on accounts, clear before reload
    lstVessels.SelectedValue = ""
    lstVessels.ClearSelection(); 
    lstVessels.Items.Clear();

     

    Perhaps Telerik would consider adding a single method which accomplishes the same task? If the context doesn't allow it to work, throw an exception or return 'false', but it seems many people could use a clean way to reset the combo. Thanks!

  28. David McClelland
    David McClelland avatar
    9 posts
    Member since:
    Oct 2012

    Posted 15 Oct 2012 Link to this post

    merikmgrasp's solution using OnClientDropDownClosed seemed to work the best for me.
  29. Mark
    Mark avatar
    2 posts
    Member since:
    Dec 2011

    Posted 23 Aug 2013 Link to this post

    After trying all the options,
    RadcomboBox1.ClearCheckedItems();
    Worked for me.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017