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.

is this using v8.5 or v9.1??

17 March 2009
Mehul Harry (DevExpress)
Mehul Harry (DevExpress)

I used version 9.1 in the demo but it should work with the 8.3 version as well.

17 March 2009

Works great except...

 When you select either one of the custom filters nothing is displayed in the filter row.  How can you display the text in the filter row to inform user that one of these filters has been set?

14 April 2009

Please login or register to post comments.