New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Filter for Built-in Checkbox Column

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:

  1. Handle the ItemCreated event of the grid to modify the Controls collection of the corresponding header cell.

  2. 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.

  3. 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.

The following example illustrates this approach:

ASP.NET
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" AllowSorting="True" AllowPaging="true"
  Width="300px" AllowFilteringByColumn="true" OnNeedDataSource="RadGrid1_NeedDataSource"
  OnItemCreated="RadGrid1_ItemCreated">
  <PagerStyle Mode="NextPrevAndNumeric" />
  <MasterTableView AutoGenerateColumns="false">
    <Columns>
      <telerik:GridCheckBoxColumn UniqueName="GridCheckBoxColumn" DataField="Bool" HeaderText="Check/UnCheck" />
      <telerik:GridBoundColumn UniqueName="ContactName" HeaderText="Contact name" DataField="ContactName" />
    </Columns>
  </MasterTableView></telerik:RadGrid>

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.

Not finding the help you need?
Contact Support