Clear ComboBox

7 posts, 1 answers
  1. Jocelyn
    Jocelyn avatar
    148 posts
    Member since:
    Jul 2012

    Posted 05 Jun 2012 Link to this post

    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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Jun 2012 Link to this post

    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.
  3. Jocelyn
    Jocelyn avatar
    148 posts
    Member since:
    Jul 2012

    Posted 20 Jun 2012 Link to this post

    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?
  4. Jagat
    Jagat avatar
    151 posts
    Member since:
    Jan 2011

    Posted 20 Jun 2012 Link to this post

    Princy,
    I think its not working when you have EnableLoadOnDemand set to 'True'.
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Jun 2012 Link to this post

    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.
  6. Syed
    Syed avatar
    8 posts
    Member since:
    Dec 2012

    Posted 09 Mar 2013 Link to this post

    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

  7. Nencho
    Admin
    Nencho avatar
    1871 posts

    Posted 13 Mar 2013 Link to this post

    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.
Back to Top