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

Clear RadComboBox text

29 Answers 1407 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Moustafa
Top achievements
Rank 1
Moustafa asked on 09 Oct 2008, 07:15 AM
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.

29 Answers, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 09 Oct 2008, 03:52 PM
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?
0
Accepted
Yana
Telerik team
answered on 10 Oct 2008, 05:38 AM
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.
0
Moustafa
Top achievements
Rank 1
answered on 11 Oct 2008, 10:29 AM

yes thank you very much, this solve the problem

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

RadComboBox1.ClearSelection();    clear the selected items

0
Kumar
Top achievements
Rank 1
answered on 12 Feb 2010, 09:46 PM

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?

0
Kamen Bundev
Telerik team
answered on 16 Feb 2010, 04:37 PM
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.
0
Kumar
Top achievements
Rank 1
answered on 22 Feb 2010, 08:49 PM

Hi Kamen,

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

0
Yana
Telerik team
answered on 25 Feb 2010, 12:30 PM
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.
0
ALAN NEMARIC
Top achievements
Rank 1
answered on 07 Apr 2010, 07:05 AM
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
0
Kalina
Telerik team
answered on 12 Apr 2010, 04:25 PM
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.
0
Hans van Rijnswoud
Top achievements
Rank 2
answered on 24 Aug 2010, 03:35 PM
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>


0
Kalina
Telerik team
answered on 27 Aug 2010, 03:41 PM
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
0
Sébastien
Top achievements
Rank 2
answered on 27 Jan 2011, 01:02 PM
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.
0
Dennys
Top achievements
Rank 1
answered on 22 Feb 2011, 05:40 PM
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.
0
Kalina
Telerik team
answered on 28 Feb 2011, 02:32 PM
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!
0
Matt DiPietro
Top achievements
Rank 1
answered on 11 Jul 2011, 06:33 PM
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.
0
Kalina
Telerik team
answered on 14 Jul 2011, 09:46 AM
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!

0
sameer
Top achievements
Rank 1
answered on 18 Jul 2011, 06:11 AM

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...

0
Kalina
Telerik team
answered on 18 Jul 2011, 04:18 PM
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!

0
Edwin
Top achievements
Rank 1
answered on 19 Jul 2011, 06:02 PM
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";
         }
0
Shinu
Top achievements
Rank 1
answered on 20 Jul 2011, 10:29 AM
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.
0
Matt DiPietro
Top achievements
Rank 1
answered on 20 Sep 2011, 07:55 PM
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?
0
Matt DiPietro
Top achievements
Rank 1
answered on 20 Sep 2011, 08:54 PM
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.
0
Dimitar Terziev
Telerik team
answered on 23 Sep 2011, 03:28 PM
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
0
Kanna
Top achievements
Rank 2
answered on 22 Dec 2011, 10:30 AM
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
0
TonyG
Top achievements
Rank 1
answered on 01 May 2012, 01:50 AM

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!

0
David McClelland
Top achievements
Rank 1
answered on 15 Oct 2012, 02:54 PM
merikmgrasp's solution using OnClientDropDownClosed seemed to work the best for me.
0
Mark
Top achievements
Rank 1
answered on 23 Aug 2013, 08:19 PM
After trying all the options,
RadcomboBox1.ClearCheckedItems();
Worked for me.
0
Raju
Top achievements
Rank 1
answered on 06 Feb 2019, 02:59 PM
                    Offred solution (not working)
                    cbo.Text = "";  ==> Not worked
                    cbo.SelectedValue = ""; ==> Not worked
                    cbo.clearSelection(); Cleared
                    cbo.clearItems(); Came Back


                    Tryed solution (working Fine)
                    cbo.clearSelection(); Cleared
                    cbo._callbackText = "";
                    cbo._filterText = "";
                    cbo.clearItems(); Works fine
0
Raju
Top achievements
Rank 1
answered on 06 Feb 2019, 03:05 PM
I know i am using private variables but no other solution worked. please suggest.
Tags
ComboBox
Asked by
Moustafa
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
Yana
Telerik team
Moustafa
Top achievements
Rank 1
Kumar
Top achievements
Rank 1
Kamen Bundev
Telerik team
ALAN NEMARIC
Top achievements
Rank 1
Kalina
Telerik team
Hans van Rijnswoud
Top achievements
Rank 2
Sébastien
Top achievements
Rank 2
Dennys
Top achievements
Rank 1
Matt DiPietro
Top achievements
Rank 1
sameer
Top achievements
Rank 1
Edwin
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Kanna
Top achievements
Rank 2
TonyG
Top achievements
Rank 1
David McClelland
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Raju
Top achievements
Rank 1
Share this question
or