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

Working with Expressions

Apart from building complex filtering criteria by means of the visual UI, RadFilter also provides the option of adding filter and group expressions programmatically. Saving and loading expressions is also supported.

RadFilter FilterExpression types

The following table describes all filter expression types you can use:

 

FilterExpression typeDescription
RadFilterBetweenFilterExpressionRepresents Between RadFilter filter expression where T is the type of the field on which filter will be applied.
RadFilterNotBetweenFilterExpressionRepresents NotBetween RadFilter filter expression where T is the type of the field on which filter will be applied.
RadFilterContainsFilterExpressionRepresents Contains RadFilter filter expression.
RadFilterGreaterThanFilterExpressionRepresents GreaterThan RadFilter filter expression where T is the type of the field on which filter will be applied.
RadFilterGreaterThanOrEqualToFilterExpressionRepresents GreaterThan or EqualTo RadFilter filter expression where T is the type of the field on which filter will be applied.
RadFilterGroupFilterExpressionRepresents a group of filter expressions.
RadFilterIsEmptyFilterExpressionRepresents IsEmpty RadFilter filter expression.
RadFilterNotIsEmptyFilterExpressionRepresents IsEmpty RadFilter filter expression.
RadFilterNotIsNullFilterExpressionRepresents IsNotNull RadFilter filter expression.
RadFilterIsNullFilterExpressionRepresents IsNull RadFilter filter expression.
RadFilterLessThanFilterExpressionRepresents LessThan RadFilter filter expression where T is the type of the field on which filter will be applied.
RadFilterLessThanOrEqualToFilterExpressionRepresents LessThan or EqualTo RadFilter filter expression where T is the type of the field on which filter will be applied.
RadFilterEqualToFilterExpressionRepresents EqualTo RadFilter filter expression where T is the type of the field on which filter will be applied.
RadFilterNotEqualToFilterExpressionRepresents NotEqualTo RadFilter filter expression where T is the type of the field on which filter will be applied.
RadFilterStartsWithFilterExpressionRepresents StartsWith RadFilter filter expression.
RadFilterEndsWithFilterExpressionRepresents EndsWith RadFilter filter expression.

Adding RadFilter expressions programmatically

You can create filter expressions as well as group expressions in the code behind. Please note that the group expressions should first be added to the RootGroup, and the filter expressions to be added to them.

In the following sample it is shown how to programmatically create a expression that filters the Orders table for orders with ShipName that starts with an 'A' and OrderDate either in the previous month, or not specified:

ASPNET
<telerik:RadFilter RenderMode="Lightweight" runat="server" ID="RadFilter1" ExpressionPreviewPosition="Bottom">
    <FieldEditors>
        <telerik:RadFilterTextFieldEditor FieldName="ShipName" />
        <telerik:RadFilterDateFieldEditor FieldName="OrderDate" />
    </FieldEditors>
</telerik:RadFilter>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="Select OrderID, OrderDate, ShipVia, ShipName, ShipAddress, ShipCity, ShipCountry FROM Orders">
</asp:SqlDataSource>

This will result in the following: filter Programmatic Expression