ASP.NET Grid Tip: How To Check For Empty Values In Header Filter

ASP.NET Team Blog
17 March 2009

Here’s a quick and useful tip for finding empty values when using the ASPxGridView’s header filter. For example, if you have a Date column:

ASPxGridView Header Filter

And you want to find all the Orders which have an ‘Empty’ ShippedDate value, then follow these 2 simple steps:

  1. Override the ASPxGridView’s HeaderFilterFillItems event
  2. Add the following 2 lines of code:


C# Version:

protected void ASPxGridView1_HeaderFilterFillItems(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewHeaderFilterEventArgs e)
  e.Values.Insert(1, new FilterValue("Empty", "", "[" + e.Column.FieldName + "] Is Null"));
  e.Values.Insert(2, new FilterValue("Not Empty", "", "[" + e.Column.FieldName + "] Is Not Null"));


VB.NET Version:

  Protected Sub ASPxGridView1_HeaderFilterFillItems(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewHeaderFilterEventArgs) Handles ASPxGridView1.HeaderFilterFillItems
    e.Values.Insert(1, New FilterValue("Empty", "", "[" & e.Column.FieldName & "] Is Null"))
    e.Values.Insert(2, New FilterValue("Non Empty", "", "[" & e.Column.FieldName & "] Is Not Null"))
  End Sub

This code create 2 new filter values for ‘Empty’ and ‘Not Empty’ which check if the field value is null:

ASPxGridView Header Filter With Empty Filter Option

Custom Filter

By using this event, you can also create custom filters which:

  • Check if a certain field value is greater 50
  • Choose which columns to add the custom filters
  • And more…

How? Check out the FilterValue Constructor help topic.

Sample Project

Here’s the sample project which contains both C# and VB.NET versions of the code. Click here to download: []

Then drop me a line here and let me know what you think of this tip. Smile

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.