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

Reset LoadOnDemand Combobox

3 Answers 127 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 15 Sep 2011, 04:30 AM
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,

3 Answers, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 15 Sep 2011, 06:29 PM
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
0
Joe
Top achievements
Rank 2
answered on 15 Sep 2011, 09:07 PM
Thanks,

However, this didnt work. :(
The selected entry is still selected. Any other thoughts?
0
Kalina
Telerik team
answered on 16 Sep 2011, 03:41 PM
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
Tags
ComboBox
Asked by
Joe
Top achievements
Rank 2
Answers by
Kalina
Telerik team
Joe
Top achievements
Rank 2
Share this question
or