Example E4218
Visible to All Users

Grid View for ASP.NET Web Forms - How to create ShowBlanksValue and ShowNonBlanksValue items in the header filter

GridViewDataComboBoxColumn does not render (Blank) and (NonBlank) items if the HeaderFilterMode property is set to CheckedList.
Call the FilterValue.CreateShowBlanksValue and FilterValue.CreateShowNonBlanksValue methods in the HeaderFilterFillItems event handler to add these items.

C#
protected void grid_HeaderFilterFillItems(object sender, ASPxGridViewHeaderFilterEventArgs e) { if (e.Column.FieldName != "CategoryNameNull") return; e.Values.Insert(0, FilterValue.CreateShowBlanksValue(e.Column, "Blanks")); e.Values.Insert(1, FilterValue.CreateShowNonBlanksValue(e.Column, "Non Blanks")); }

Files to Review

Example Code

WebSite/Default.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register assembly="DevExpress.Web.v13.1, Version=13.1.14.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web" tagprefix="dx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>ASPxGridView - How to create the ShowBlanksValue aand ShowNonBlanksValue items</title> </head> <body> <form id="form1" runat="server"> <div> <dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="dsCategories" KeyFieldName="CategoryID" OnHeaderFilterFillItems="grid_HeaderFilterFillItems"> <Columns> <dx:GridViewDataTextColumn FieldName="CategoryID"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="Description"> </dx:GridViewDataTextColumn> <dx:GridViewDataComboBoxColumn FieldName="CategoryNameNull" Caption="Category Name"> <Settings HeaderFilterMode="CheckedList" /> <PropertiesComboBox DataSourceID="dsCategories" ValueField="CategoryNameNull" TextField="CategoryNameNull" /> </dx:GridViewDataComboBoxColumn> </Columns> <Settings ShowHeaderFilterButton="true" /> </dx:ASPxGridView> <asp:AccessDataSource ID="dsCategories" runat="server" DataFile="~/App_Data/nwind.mdb" SelectCommand="SELECT [CategoryID], [Description], [CategoryNameNull] FROM [Categories]"> </asp:AccessDataSource> </div> <div> </div> </form> </body> </html>
WebSite/Default.aspx.cs(vb)
C#
using System; using System.Collections.Generic; using System.Linq; using DevExpress.Web; public partial class _Default : System.Web.UI.Page { protected void grid_HeaderFilterFillItems(object sender, ASPxGridViewHeaderFilterEventArgs e) { if (e.Column.FieldName != "CategoryNameNull") return; e.Values.Insert(0, FilterValue.CreateShowBlanksValue(e.Column, "Blanks")); e.Values.Insert(1, FilterValue.CreateShowNonBlanksValue(e.Column, "Non Blanks")); } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.