New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Load On Demand Overview

RadComboBox provides its own Load-On-Demand mechanism. A poll-server timeout could be set, and RadComboBox fires a server-side event (ItemsRequested) which returns items based on the current text. RadComboBox also provides an option to cache the items loaded on demand. Starting from the Q1 2010 release, RadComboBox supports automatic (codeless) Load On Demand.

To use the Load-On-Demand mechanism, you need to:

  • Set the EnableLoadOnDemand property to True;

  • Do one of the following:

  • Subscribe to the ItemsRequested event and add new items to the RadComboBox.

Items added in the ItemsRequested event handler are cleared when the next ItemsRequested event fires. If you, however, use the ShowMoreResultsBox mechanism or Virtual Scrolling the items will not be cleared upon clicking the ShowMoreResultsBox arrow or scrolling down.

When the user types in the input area or clicks on the drop-down toggle image when there are no items in the RadComboBox, the OnClientItemsRequesting event fires on the client, followed by an ItemsRequested event on the server. Once the new items have been added to RadComboBox, an OnClientItemsRequested event fires on the client.

The EnableLoadOnDemand property allows the user to enter text in the input area, regardless of the value of the AllowCustomText property. This is because the load-on-demand mechanism requires the user to be able to enter text.

To specify a timeout (in milliseconds) before the server event is executed, use the ItemRequestTimeout.

Example

The ItemsRequested event handler shown below fills the RadComboBox with a set of items, loaded from a database. The items' text must match the string typed in the input area of the RadComboBox:


protected void RadComboBox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
   RadComboBox combo = (RadComboBox) o;

   string mdbPath = Server.MapPath("App_Data/NWind.mdb");
   OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath);
   dbCon.Open();

   string sql = "SELECT * from Customers WHERE CompanyName LIKE '" + e.Text + "%'";

   OleDbDataAdapter adapter = new OleDbDataAdapter(sql, dbCon);
   DataTable dt = new DataTable();
   adapter.Fill(dt);
   dbCon.Close();

   foreach (DataRow row in dt.Rows)
   {
         RadComboBoxItem item = new RadComboBoxItem(row["CompanyName"].ToString());
         combo.Items.Add(item);
   }
}


Protected Sub RadComboBox1_ItemsRequested(ByVal o As Object, ByVal e As RadComboBoxItemsRequestedEventArgs) Handles RadComboBox1.ItemsRequested
    Dim combo As RadComboBox = DirectCast(o, RadComboBox)
    Dim mdbPath As String = Server.MapPath("App_Data/NWind.mdb")
    Dim dbCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath)
    dbCon.Open()
    Dim sql As String = "SELECT * from Customers WHERE CompanyName LIKE '" + e.Text + "%'"
    Dim adapter As New OleDbDataAdapter(sql, dbCon)
    Dim dt As New DataTable()
    adapter.Fill(dt)
    dbCon.Close()
    For Each row As DataRow In dt.Rows
        Dim item As New RadComboBoxItem(row("CompanyName").ToString())
        combo.Items.Add(item)
    Next
End Sub

Additional online examples can be found in the following links:

See Also

In this article