Back to Devexpress

How to: Add Custom Filter Values to the Filter Dropdown

aspnet-4025-components-grid-view-examples-how-to-add-custom-filter-values-to-the-filter-dropdown.md

latest1.3 KB
Original Source

How to: Add Custom Filter Values to the Filter Dropdown

  • Sep 30, 2021

This example creates custom filter items and displays them within the Units On Order column’s filter dropdown.

csharp
protected void ASPxGridView1_HeaderFilterFillItems(object sender, DevExpress.Web.ASPxGridViewHeaderFilterEventArgs e) {
        if (e.Column.FieldName != "Quantity") return;
        e.AddValue("nonzero", string.Empty, "[Quantity] != 0");
        e.AddValue(String.Format("from {0} to {1}", 0, 50), string.Empty, String.Format("[Quantity] > {0} and [Quantity] < {1}", 0, 50));
        e.AddValue(String.Format(">= {0}", 50), string.Empty, String.Format("[Quantity] >= {0}", 50));
}
vb
Protected Sub ASPxGridView1_HeaderFilterFillItems(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewHeaderFilterEventArgs)
    If e.Column.FieldName <> "Quantity" Then Return
    e.AddValue("nonzero", String.Empty, "[Quantity] != 0")
    e.AddValue(String.Format("from {0} to {1}", 0, 50), String.Empty, String.Format("[Quantity] > {0} and [Quantity] < {1}", 0, 50))
    e.AddValue(String.Format(">= {0}", 50), String.Empty, String.Format("[Quantity] >= {0}", 50))
End Sub