[Solved] Filter Template Column with Boolean Datafield error

1 Answer 28 Views
Grid
Fit2Page
Top achievements
Rank 3
Bronze
Bronze
Iron
Fit2Page asked on 30 Oct 2026, 09:48 AM

Hi,

 

I am trying to filter a Template Column with Boolean dataType like so:

<telerik:GridTemplateColumn UniqueName="AfhKwaliteit" DataField="AfhKwaliteit" DataType="System.Boolean" AutoPostBackOnFilter="True" CurrentFilterFunction="EqualTo" FilterDelay="4000" ShowFilterIcon="False">
<ItemTemplate>
<asp:Label TabIndex="1" runat="server" Text='<%#IIf(Container.DataItem("AfhKwaliteit"), "<i class=""fas fa-check-circle text-success""></i>", "<i class=""fas fa-times-circle text-danger""></i>") %>' />
</ItemTemplate>
</telerik:GridTemplateColumn>

When applying a check in one of the filter checkboxes we get:

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Unable to cast object of type 'System.Web.UI.WebControls.CheckBox' to type 'System.Web.UI.WebControls.TextBox'.

See also attached screenshot.

How should the settings be to filter on boolean values og these four columns?

 

Marc

 

1 Answer, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 30 Oct 2026, 02:12 PM

Hello Marc,

Thank you for the shared code snippet.

The error occurs because the default filtering mechanism for GridTemplateColumn expects a TextBox, but your column holds Boolean values and needs a CheckBox for filtering. To filter Boolean values in a GridTemplateColumn, you must use a custom filter template with a CheckBox and handle the filtering logic in the code-behind.

To apply filtering for all four Boolean columns, follow these steps for each column:

  • Use a <FilterTemplate> with a CheckBox inside your GridTemplateColumn.
  • Set the column’s DataType to System.Boolean.
  • Handle the CheckBox’s CheckedChanged event in the code-behind to apply the filter.
  • Set AutoPostBackOnFilter="True" to trigger filtering automatically.
<telerik:GridTemplateColumn UniqueName="AfhKwaliteit"
    DataField="AfhKwaliteit"
    DataType="System.Boolean"
    AutoPostBackOnFilter="True"
    CurrentFilterFunction="EqualTo"
    ShowFilterIcon="False">
    <ItemTemplate>
        <asp:Label runat="server" Text='<%# ((bool)Eval("AfhKwaliteit")) ? "<i class=\"fas fa-check-circle text-success\"></i>" : "<i class=\"fas fa-times-circle text-danger\"></i>" %>' />
    </ItemTemplate>
    <FilterTemplate>
        <asp:CheckBox ID="chkFilterAfhKwaliteit" runat="server" AutoPostBack="true" OnCheckedChanged="chkFilterAfhKwaliteit_CheckedChanged" />
    </FilterTemplate>
</telerik:GridTemplateColumn>
    protected void chkFilterAfhKwaliteit_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chk = sender as CheckBox;
        GridColumn column = RadGrid1.MasterTableView.GetColumn("AfhKwaliteit");
        column.CurrentFilterFunction = GridKnownFunction.EqualTo;
        column.CurrentFilterValue = chk.Checked.ToString();
        RadGrid1.MasterTableView.FilterExpression = column.EvaluateFilterExpression();
        RadGrid1.MasterTableView.Rebind();
    }
    

    Try this approach and let me know it it works for your scenario.

      Regards,
      Vasko
      Progress Telerik

      Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources! 
      Fit2Page
      Top achievements
      Rank 3
      Bronze
      Bronze
      Iron
      commented on 02 Nov 2026, 09:23 AM

      Hi Vasko,

       

      Works very well in our setup, thank you!

       

      Marc

      Tags
      Grid
      Asked by
      Fit2Page
      Top achievements
      Rank 3
      Bronze
      Bronze
      Iron
      Answers by
      Vasko
      Telerik team
      Share this question
      or