The default drop-down list of filter functions for GridCheckBoxColumn contains the following items:
NoFilter
EqualTo
NotEqualTo
IsNull
NotIsNull
Consider the case when you want to remove the "IsNull" and "NotIsNull" items from the check box column, while leaving them available for other columns in the grid. One approach to this is to replace the default text box and image button with a drop-down list that contains the possible options ("Clear Filter", "Show all checked", and "Show all unchecked).
To replace the default textbox filter for GridCheckBoxColumn, you can do the following:
Handle the ItemCreated event of the grid to modify the Controls collection of the corresponding header cell.
Handle the SelectedIndexChanged event of the drop-down list (which appears in the place of the textbox) to modify the grid FilterExpression so that it reflects the SelectedValue of the drop-down list you added.
In the NeedDataSource event handler, add the check box column's filter expression to the FilterExpression property of the table so that it is honored when the user triggers a filter action from another column.
ProtectedSub RadGrid1_ItemCreated(ByVal sender AsObject, _
ByVal e As Telerik.Web.UI.GridItemEventArgs) _
Handles RadGrid1.ItemCreated
If(TypeOf e.Item Is GridFilteringItem)ThenDim filteringItem As GridFilteringItem =CType(e.Item, GridFilteringItem)
filteringItem("GridCheckBoxColumn").Controls.Clear()Dim ddList As DropDownList =New DropDownList()
ddList.AutoPostBack =TrueAddHandler ddList.SelectedIndexChanged,AddressOf ddList_SelectedIndexChanged
ddList.Items.Add(New ListItem("Clear filter","Empty"))
ddList.Items.Add(New ListItem("Show all checked","True"))
ddList.Items.Add(New ListItem("Show all unchecked","False"))If(Not Session("ddlSelValue")IsNothing)Then
ddList.Items.FindByValue(CType(Session("ddlSelValue"),String)).Selected =TrueEndIf
filteringItem("GridCheckBoxColumn").Controls.Add(ddList)EndIfEndSubProtectedSub ddList_SelectedIndexChanged(ByVal sender AsObject, _
ByVal e AsSystem.EventArgs)Dim ddList As DropDownList =CType(sender, DropDownList)
Session("ddlSelValue")= ddList.SelectedValue
Select Case ddList.SelectedValue
Case"True"
RadGrid1.MasterTableView.FilterExpression ="([Bool] = True) "For Each column As GridColumn In RadGrid1.MasterTableView.Columns
column.CurrentFilterFunction = GridKnownFunction.NoFilter
column.CurrentFilterValue =String.Empty
Next
RadGrid1.MasterTableView.Rebind()Case"False"
RadGrid1.MasterTableView.FilterExpression ="([Bool] = False) "For Each column As GridColumn In RadGrid1.MasterTableView.Columns
column.CurrentFilterFunction = GridKnownFunction.NoFilter
column.CurrentFilterValue =String.Empty
Next
RadGrid1.MasterTableView.Rebind()Case"Empty"
RadGrid1.MasterTableView.FilterExpression =String.Empty
For Each column As GridColumn In RadGrid1.MasterTableView.Columns
column.CurrentFilterFunction = GridKnownFunction.NoFilter
column.CurrentFilterValue =String.Empty
Next
RadGrid1.MasterTableView.Rebind()EndSelectEndSubPublicShared connectionString AsString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&System.Web.HttpContext.Current.Server.MapPath("~/Grid/Data/Access/Nwind.mdb")PublicFunction GetDataTable(ByVal query AsString)As DataTable
Dim connection1 AsNew OleDbConnection(connectionString)Dim adapter1 AsNew OleDbDataAdapter
adapter1.SelectCommand =New OleDbCommand(query, connection1)Dim table1 AsNew DataTable
connection1.Open()Try
adapter1.Fill(table1)Finally
connection1.Close()EndTryReturn table1
EndFunctionProtectedSub RadGrid1_NeedDataSource(ByVal source AsObject, _
ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) _
Handles RadGrid1.NeedDataSource
RadGrid1.DataSource = GetDataTable("Select ContactName, Bool FROM Customers")If(Not Session("ddlSelValue")IsNothing)ThenIf(Not Session("ddlSelvalue")="Empty")Then
RadGrid1.MasterTableView.FilterExpression = _
RadGrid1.MasterTableView.FilterExpression & _
"AND ([Bool] = "&CType(Session("ddlSelValue"),String)&")"EndIfEndIfEndSub
With the .NET 3.5 build of RadGrid for ASP.NET AJAX and LINQ filter expressions enabled (EnableLinqExpressions = true), the filter expressions set for the grid either internally by its filtering mechanism or manually in code should conform to the LINQ expression syntax instead of the old T-SQL syntax. Only thus they will be evaluated properly by the control.