Blogs

News

Email Subscriptions

Mehul Harry's DevExpress Blog

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

     

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: [GridCustomHeaderFilter.zip]

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

Published Mar 17 2009, 03:08 PM by Mehul Harry (DevExpress)
Bookmark and Share

Comments

 

awake said:

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

March 17, 2009 7:15 PM
 

Mehul Harry (DevExpress) said:

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

March 17, 2009 7:43 PM
 

Paul said:

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?

April 14, 2009 12:05 PM

About Mehul Harry (DevExpress)

Mehul Harry is an ASP.NET technical evangelist at Developer Express. You can reach him directly at mharry@DevExpress.com. You can also follow him on Twitter: http://twitter.com/mehulharry
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.