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:
- I'm using rad controls for asp.net ajax
- the RadComboBox allow Custom Text so user can type what need.
29 Answers, 1 is accepted
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?
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.
yes thank you very much, this solve the problem
RadComboBox1.Text = ""; //clear the custom text
RadComboBox1.ClearSelection(); clear the selected items
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?
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.
Hi Kamen,
Here I am not using RadComboBox as a 'ReadOnly". It seems to be RadComboBox1.Text has some problems.
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 =
""
;
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.
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
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.
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
>
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
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.
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
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!
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...
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!
<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"
;
}
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.
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?
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.
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
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
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!
RadcomboBox1.ClearCheckedItems();
Worked for me.
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