Reset LoadOnDemand Combobox

4 posts, 0 answers
  1. Joe
    Joe avatar
    23 posts
    Member since:
    Nov 2010

    Posted 14 Sep 2011 Link to this post

    I have a method that I use to reset a form after a submit or if the user chooses to click a reset button. For the most part it works, however if Im using a combobox that is tied to a LoadOnDemand event, the selected item is still displayed. It does appear that the remaining items are reloaded when I click the dropdown arrow.

    Here is the code I'm using:

    public static void resetForm(Control parent)
     {
         foreach (Control c in parent.Controls)
         {
             if (c.Controls.Count > 0)
             {
                 resetForm(c);
             }
             else
             {
                 switch (c.GetType().ToString())
                 {
                     case "Telerik.Web.UI.RadTextBox":
                         ((RadTextBox)c).Text = "";
                         break;
     
                     case "Telerik.Web.UI.RadComboBox":
                         ((RadComboBox)c).ClearSelection();
                         ((RadComboBox)c).Text = string.Empty;
     
                         break;
     
                     case "Telerik.Web.UI.RadTimePicker":
                         ((RadTimePicker)c).Clear();
                         break;
     
                     case "Telerik.Web.UI.RadDatePicker":
                         ((RadDatePicker)c).Clear();
                         break;
     
                     case "System.Web.UI.WebControls.CheckBox":
                         ((CheckBox)c).Checked = false;
                         break;
     
                 }
             }
         }
     }

    Thanks,
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 15 Sep 2011 Link to this post

    Hello Joe,

    You can try resetting RadComboBox by clearing its SelectedValue and Text:

    <telerik:RadComboBox ID="RadComboBox1"
        runat="server"
        OnItemsRequested="OnItemsRequested" 
        DataTextField="DisplayName"
        DataValueField="ID"            
        EnableLoadOnDemand="True" >
    </telerik:RadComboBox>
    <asp:Button ID="btnSubmit" runat="server"  OnClick="OnClick" />

    protected void OnClick(object sender, EventArgs e)
    {
        RadComboBox1.SelectedValue = "";
        RadComboBox1.Text = "";
         
    protected void OnItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        RadComboBox1.DataSource = CreateDataSource();
        RadComboBox1.DataBind();
    }
     
    protected DataTable CreateDataSource()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("ID", typeof(string)));
        dt.Columns.Add(new DataColumn("DisplayName", typeof(string)));
     
     
        DataRow dr = dt.NewRow();
        dr["ID"] = "1";
        dr["DisplayName"] = "Name 1";
        dt.Rows.Add(dr);
     
        DataRow dr2 = dt.NewRow();
        dr2["ID"] = "2";
        dr2["DisplayName"] = "Name 2";
        dt.Rows.Add(dr2);
     
        DataRow dr3 = dt.NewRow();
        dr3["ID"] = "3";
        dr3["DisplayName"] = "Name 3";
        dt.Rows.Add(dr3);
     
        return dt;
     
    }

    All the best,
    Kalina
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joe
    Joe avatar
    23 posts
    Member since:
    Nov 2010

    Posted 15 Sep 2011 Link to this post

    Thanks,

    However, this didnt work. :(
    The selected entry is still selected. Any other thoughts?
  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 16 Sep 2011 Link to this post

    Hello Joe,

    Please find the example attached and give it a try.
    I suppose that there is something in your implementation that prevents clearing the selection in RadComboBox.
    Can you modify the code of the example in order to reproduce the issue, and then paste the code here using the "format code" tool?

    All the best,
    Kalina
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
Back to Top