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

Clear ComboBox

6 Answers 140 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 05 Jun 2012, 07:07 PM
Hi,

I lost about 2 hours trying to find my problem.

I am trying to clear the selection (server side) of a RadComboBox using LoadOnDemand after the user clicked on a radio button.

For the moment, I am trying this, but this is not working:

cboChambreA.Text = Nothing
cboChambreA.ClearSelection()

How can I clear or set the selected item to nothing?

Thanks.

- Jocelyn

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Jun 2012, 04:53 AM
Hi Jocelyn,

Here is the sample code which I tried based on your scenario which works as expected.

ASPX:
<asp:RadioButton runat="server" ID="RadioButton1" AutoPostBack="true"  oncheckedchanged="RadioButton1_CheckedChanged" />

C#:
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        RadComboBox1.Text = "";
        RadComboBoxLoad.ClearSelection();
    }

Thanks,
Princy.
0
Jocelyn
Top achievements
Rank 1
answered on 20 Jun 2012, 12:56 PM
Hi,

this is not working for me. Here is my ComboBox:

<telerik:RadComboBox ID="cboPatient" runat="server" Width="300px" Height="200px"
    MarkFirstMatch="True" EnableLoadOnDemand="true" DataTextField="Nom" DataValueField="pati_noauto"
    HighlightTemplatedItems="True" LoadingMessage="Chargement" ItemsPerRequest="10"
    AutoPostBack="true" ShowMoreResultsBox="True" EnableVirtualScrolling="True" OnItemsRequested="cboPatient_ItemsRequested"
    OnClientSelectedIndexChanged="patient_IndexChanged">
  
</telerik:RadComboBox>

Can you see something that could prevent me from clearing my ComboBox?

Edit: I tried client side with $find("edPatient").clearSelection(); and it works, but is there a way to do it server side?
0
Jagat
Top achievements
Rank 1
answered on 20 Jun 2012, 05:17 PM
Princy,
I think its not working when you have EnableLoadOnDemand set to 'True'.
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 Jun 2012, 05:52 AM
Hi,

Unfortunately I couldn't replicate the issue. Here is the sample code that I tried and working as expected at my end.

ASPX:
<telerik:RadComboBox ID="cboPatient" runat="server" Width="300px" Height="200px" MarkFirstMatch="True" EnableLoadOnDemand="true" DataTextField="FirstName" DataValueField="FirstName" DataSourceID="SqlDataSource1" HighlightTemplatedItems="True" LoadingMessage="Chargement"  ItemsPerRequest="10" AutoPostBack="true" ShowMoreResultsBox="True" EnableVirtualScrolling="True">
</telerik:RadComboBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" />

C#:
protected void Button1_Click(object sender, EventArgs e)
    {
        cboPatient.Text = "";
        cboPatient.ClearSelection();
    }

Hope this helps.

Thanks,
Princy.
0
Hamid
Top achievements
Rank 1
answered on 09 Mar 2013, 06:40 PM
I also could not get RadComboBox.ClearSelection() to work, Did all the steps mentioned in this thread. 
Got it to work with the following code. Posting is here as it might help others
One important point that may be relevant is that I am using Checkboxes in my Combobox.

    Protected Sub ClearRadCB()
        Dim RadCB As RadComboBox = RadComboBoxRelations

        If Not RadCB Is Nothing Then
            For i = 0 To RadCB.Items.Count - 1
                If RadCB.Items(i).Checked Then
                    RadCB.Items(i).Checked = False
                End If
            Next i
        End If
    End Sub

Then you can call ClearRadCB() in your code or paste in the event procedure.

Thanks
Hamid

0
Nencho
Telerik team
answered on 13 Mar 2013, 02:33 PM
Hello Syed,

The ClearSelection() method could be used in a non-checkboxes scenario. When you had enabled the CheckBox feature, you could simply invoke the ClearCheckedItems() on the RadComboBox, in order to achieve the desired scenario.

Regards,
Nencho
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.
Tags
ComboBox
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jocelyn
Top achievements
Rank 1
Jagat
Top achievements
Rank 1
Hamid
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or