Back to Devexpress

ASPxGridViewAutoFilterEventArgs Class

aspnet-devexpress-dot-web-b2f5774e.md

latest3.5 KB
Original Source

ASPxGridViewAutoFilterEventArgs Class

Provides data for the ASPxGridView.ProcessColumnAutoFilter event.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public class ASPxGridViewAutoFilterEventArgs :
    GridAutoFilterEventArgs
vb
Public Class ASPxGridViewAutoFilterEventArgs
    Inherits GridAutoFilterEventArgs

ASPxGridViewAutoFilterEventArgs is the data class for the following events:

Example

In this example, the ASPxGridView.ProcessColumnAutoFilter event is handled to allow end-users to filter employees by the year of birth.

Since the BirthDate column displays DateTime values, the DateTime editor is used to specify the filter criteria. To allow end-users to only enter the year, the default editor is replaced with the text editor within the ASPxGridView.AutoFilterCellEditorCreate event handler.

The image below shows the result:

csharp
using DevExpress.Web.ASPxEditors;
using DevExpress.Data.Filtering;

protected void ASPxGridView1_ProcessColumnAutoFilter(object sender,
    DevExpress.Web.ASPxGridViewAutoFilterEventArgs e) {
    if(e.Column != ASPxGridView1.Columns["BirthDate"]) return;

    if (e.Kind == DevExpress.Web.GridViewAutoFilterEventKind.CreateCriteria) {
        // Creates a new filter criterion and applies it.
        e.Criteria = null;
        int year;
        if (!int.TryParse(e.Value, out year)) return;
        e.Criteria = (new OperandProperty("BirthDate") >= new DateTime(year, 1, 1)) &
                          (new OperandProperty("BirthDate") < new DateTime(year + 1, 1, 1));
    }
    else {
        DateTime res;
        if (!DateTime.TryParse(e.Value, out res)) {
            e.Value = string.Empty;
        }
        else {
            // Specifies the text displayed within the auto-filter row cell.
            e.Value = res.Year.ToString();
        }
    }
}
protected void ASPxGridView1_AutoFilterCellEditorCreate(object sender,
     DevExpress.Web.ASPxGridViewEditorCreateEventArgs e) {

    // Replaces the default editor used to edit DateTime values with the text editor.
if (e.Column == ASPxGridView1.Columns["BirthDate"]) e.EditorProperties = new TextBoxProperties();
}

Inheritance

Object EventArgs GridAutoFilterEventArgs ASPxGridViewAutoFilterEventArgs BootstrapGridViewAutoFilterEventArgs

See Also

ASPxGridViewAutoFilterEventArgs Members

Grid View

DevExpress.Web Namespace