Skip to content

Create a filter expression based on an editor's selected values and use this expression to filter another editor's data.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-lookup-filter-data-based-on-another-editor-selection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid Lookup for ASP.NET Web Forms - How to filter an editor's data based on selected values of another editor

This example demonstrates how to create a filter expression based on an editor's selected values and use this expression to filter another editor's data.

Filter Grid Lookup Control

Overview

Create two grid lookup editors and populate them with records. Handle the secondary editor's server-side Init event and add a CustomCallback event handler.

protected void glProducts_Init(object sender, EventArgs e) {
    ASPxGridLookup gridLookup = sender as ASPxGridLookup;
    gridLookup.GridView.CustomCallback += new ASPxGridViewCustomCallbackEventHandler(gridView_CustomCallback);
    if (Session["FilterExpression"] != null) {
        gridLookup.GridView.DataSource = adsProducts;
        adsProducts.FilterExpression = Session["FilterExpression"].ToString();
    }
}

To send a callback to the server when the primary editor's selection changes, handle the editor's client-side ValueChanged event.

<dx:ASPxGridLookup ID="glCategories" runat="server" ClientInstanceName="glCategories" SelectionMode="Multiple" ...>
    <!-- ... -->
    <ClientSideEvents ValueChanged="function(s, e) {
        var grid = glProducts.GetGridView();
        grid.PerformCallback('ValueChanged');
    }" />
</dx:ASPxGridLookup>

Handle the secondary editor's CustomCallback event. In the handler, define a filter expression to bind the secondary editor to a data source based on the selected values in the primary editor.

public void gridView_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
    if (e.Parameters != "ValueChanged") return;

    ASPxGridView grid = sender as ASPxGridView;
    var selectedValues = glCategories.GridView.GetSelectedFieldValues(glCategories.KeyFieldName);
    if (selectedValues.Count == 0)
        selectedValues.Add(-1);
    CriteriaOperator selectionCriteria = new InOperator(glCategories.KeyFieldName, selectedValues);
    adsProducts.FilterExpression = (GroupOperator.Combine(GroupOperatorType.And, selectionCriteria)).ToString();
    Session["FilterExpression"] = adsProducts.FilterExpression;
    grid.DataSource = adsProducts;
    grid.DataBind();
}

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Create a filter expression based on an editor's selected values and use this expression to filter another editor's data.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •