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

Dynamically Created RadComboBox

2 Answers 280 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Zash
Top achievements
Rank 1
Zash asked on 11 Nov 2011, 07:01 PM
Hi,

I created radcombobox dynamically. I want to add EnableLoadOnDemand functionality from codebehind. I need a sample of code in asp.net having this functionality doing from codebehind.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Nov 2011, 04:32 AM
Hello Zash,

You can try the following code snippet.

C#:
protected void Page_Load(object sender, EventArgs e)
   {
    RadComboBox rdcmb = new RadComboBox();
    rdcmb.ID = "RadComboBox1";
    rdcmb.AutoPostBack = true;
    rdcmb.MarkFirstMatch = true;
    rdcmb.AutoCompleteSeparator = ",";
    rdcmb.EnableLoadOnDemand = true;
    rdcmb.EnableAutomaticLoadOnDemand = true;
    rdcmb.LoadingMessage = "Loading...";
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ToString());
    String s = "select FirstName,EmployeeID from Employees";
    con.Open();
    SqlDataAdapter dr = new SqlDataAdapter(s, con);
    DataTable dt = new DataTable();
    dr.Fill(dt);
    con.Close();
    rdcmb.DataSource = dt;
    rdcmb.DataTextField = "FirstName";
    rdcmb.DataValueField = "EmployeeID";
    rdcmb.DataBind();
    form1.Controls.Add(rdcmb);
   }

Thanks,
Princy.
0
Ivana
Telerik team
answered on 16 Nov 2011, 11:36 AM
Hello Rukunuz,

To see how RadComboBox is bound to various data sources, you could refer to the DataBinding section of the Combo's online documentation.

To enable the load on demand functionality, you need to set the property LoadOnDemand to true, and subscribe to the OnItemsRequested server-side event, where the items will be populated when they are requested on demand (which happens when the user opens the drop-down list, or type in the input field), as in the code-block below:
protected void Page_Load(object sender, EventArgs e)
{
    RadComboBox combo = new RadComboBox();
    combo.ID = "RadComboBox1";
    combo.EnableLoadOnDemand = true;
    combo.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(combo_ItemsRequested);
    form1.Controls.Add(combo);
}
protected void combo_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    for (int i = 0; i <= 3; i++)
    {
        combo.Items.Add(new RadComboBoxItem("item_" + i.ToString()));
    }
}

More about load on demand mechanism, could be found at the following help article: RadComboBox: LoadOnDeman.

All the best,
Ivana
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
Zash
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ivana
Telerik team
Share this question
or