Friday, November 18, 2011

RadComboBox EnableLoadOnDemand

Problem: 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.
Solution: 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()));
    }
}

No comments:

Post a Comment