Blogs

This Blog

Subscribe (RSS, Email)

Mehul Harry's DevExpress Blog

JavaScript, HTML 5, ASP.NET, DevExpress, ASP.NET MVC & WebForms, and News - 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
Bookmark and Share

Comments

awake

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

March 17, 2009 7:15 PM

Mehul Harry (DevExpress)

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

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
LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, Silverlight, ASP.NET, WinForms, HTML5 or Windows 8, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2014 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners