Tab

ASPxComboBox.ItemRequestedByValue Event

Handle this event to implement retrieval of an item by its value.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v21.1.dll

Declaration

public event ListEditItemRequestedByValueEventHandler ItemRequestedByValue

Event Data

The ItemRequestedByValue event's data class is ListEditItemRequestedByValueEventArgs. The following properties provide information specific to this event:

Property Description
Text Gets a string representing text of an item (entered or selected on the client side).
Value Gets an object that is the requested item’s value.

Remarks

The ASPxComboBox provides you with the capability to dynamically populate a dropdown list with the required items. To implement this mode, it is necessary to handle both the ASPxComboBox.ItemsRequestedByFilterCondition and ItemRequestedByValue events.

The ItemRequestedByValue event is raised when an ASPxComboBox editor needs to obtain a particular item specified by its value (ListEditItemRequestedByValueEventArgs.Value) from a data source. This event is usually raised when the server loads postback data (e.g., when filtering or validating data). It is also raised if the ASPxComboBox.Value property is set to a nonzero value, which is not contained in the ASPxAutoCompleteBoxBase.Items collection, before the control is rendered.

In the ItemRequestedByValue event handler, bind the ASPxComboBox control to a collection containing a single item with the specified value. For more information, see the Dynamic List Population (Filtering Large Data Sources) help topic.

The ItemRequestedByValue event can be raised with the e.Value = null when nothing is explicitly selected/confirmed and the current editor’s Value is null.

When the entered filter does not return any results, the following scenarios are possible:

  • If the filter is explicitly confirmed, the e.Value should be equal to this filter;
  • If not, the ASPxComboBox is bound to an empty collection.

The ASPxComboBox.ValueType property is primarily intended for items, while the ASPxComboBox.Value property can be null. This situation is for scenarios when users specifically add an item whose Value property is null in order to explicitly select this item within the ASPxComboBox when its Value is null.

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();
}
See Also