Dynamic List Population (Filter Large Data Sources)

  • 3 minutes to read

The ASPxComboBox allows you to manually populate a dropdown list with the required item portions, based on the currently applied filter criteria and the scroll actions performed by a user. For instance, if you bind to a large data source, you can specify that only a few records be visible on screen. You can load the rest of the items on demand, while a user scrolls the list.

In this mode, all data-aware operations (such as filtering) are executed on the database server side. This allows you to decrease the web server workload because you load only a subset of all items (for large data sets), which improves data processing and display speeds.

To manually supply list data to the ASPxComboBox editor, enable callback mode (set the ASPxAutoCompleteBoxBase.EnableCallbackMode property to True) and handle the following two events: ASPxComboBox.ItemsRequestedByFilterCondition and ASPxComboBox.ItemRequestedByValue.

If you handle these events and use the ASPxComboBox editor's 'Contains' filter mode, you can allow users to search more efficiently against a large amount of data.

Online Demo

Example

The following section of the Filtering Large Data Source online demo illustrates how the ASPxComboBox.ItemsRequestedByFilterCondition and ASPxComboBox.ItemRequestedByValue events of the ASPxComboBox editor can be handled to filter the editor's data source containing a large number of records.

NOTE

To work properly, both the ItemsRequestedByFilterCondition and ItemRequestedByValue events should be handled.

protected void ASPxComboBox_OnItemsRequestedByFilterCondition_SQL(object source, 
ListEditItemsRequestedByFilterConditionEventArgs e) {
         ASPxComboBox comboBox = (ASPxComboBox)source;
         SqlDataSource1.SelectCommand = @"SELECT OID, [From], Sent, Subject 
             FROM (select OID, [From], Sent, Subject, row_number() over(order by t.Sent) as [rn] 
             from dbo.ServerSideGridTest as t WHERE ((t.Subject LIKE @filter) OR (t.[From] 
              LIKE @filter))) as st where st.[rn] between @startIndex and @endIndex";
         SqlDataSource1.SelectParameters.Clear();
         SqlDataSource1.SelectParameters.Add("filter", TypeCode.String, string.Format("%{0}%", e.Filter));
         SqlDataSource1.SelectParameters.Add("startIndex", TypeCode.Int64, (e.BeginIndex + 1).ToString());
         SqlDataSource1.SelectParameters.Add("endIndex", TypeCode.Int64, (e.EndIndex + 1).ToString());
         comboBox.DataSource = SqlDataSource1;
         comboBox.DataBind();
}

protected void ASPxComboBox_OnItemRequestedByValue_SQL(object source, 
ListEditItemRequestedByValueEventArgs e) {
    ASPxComboBox comboBox = (ASPxComboBox)source;
    SqlDataSource1.SelectCommand = @"SELECT OID, Subject, [From], Sent 
        FROM dbo.ServerSideGridTest WHERE (OID = @OID) ORDER BY Sent";
    SqlDataSource1.SelectParameters.Add("OID", TypeCode.Int64, e.Value.ToString());
    ...
    comboBox.DataSource = SqlDataSource1;
    comboBox.DataBind();
}