$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
Filter Expressions in ASP.NET
Home > How to > Filter Expressions

Kettic Filter control, one of the composing components for Kettic UI ASP.NET AJAX suite, is especially designed to provide developers with outstanding ability to build and create related expressions for accurate filtering.
In this tutorial, we will mainly focus on introducing some important filter expressions and provide you with detailed sample codes to help you get started easily. We will introduce some basic filter expression types first, followed by filter expression loading and saving methods.

Filter Expression Introduction

  • PerFilterBetweenFilterExpression<T>: This is applied to represent Between expression, in which the letter T stands for the files types which you will apply filter later.
  • PerFilterNotBetweenFilterExpression<T>: This is used to represent the NotBetween expression for the filed type to apply filter.
  • PerFilterContainsFilterExpression: This expression can be applied for Contains filtering.
  • PerFilterGreaterThanFilterExpression<T>: You can use this expression for GreaterThan filtering, and the letter T stands for field type to be applied filter later on.
  • PerFilterGreaterThanOrEqualToFilterExpression<T>: Use this expression for GreaterThanOrEqualTo filtering to apply for field type specified by the letter T.
  • PerFilterGroupFilterExpression: This is used to specify a batch of filter expressions.
  • PerFilterIsEmptyFilterExpression: This expression represents IsEmpty filtering.
  • PerFilterIsNullExpression: This can represent the IsNull filter expression.
  • PerFilterLessThanFilterExpression: This is used to apply LessThan filter expression for field type specified by the letter T.
  • PerFilterNotEqualToFilterExpression<T>: This simply represents NotEqualTo filter expression for field type specified by the letter T.
  • PerFilterStartsWithFilterExpression: This represents the StartsWith filter expression.
  • PerFilterEndsWithFilterExpression: This represents the EndsWith filter expression.
This is a C# code demo for some of the filter expressions introduced above:
PerFilterContainsFilterExpression firstName = new PerFilterContainsFilterExpression("FirstName");
firstName.Value = "Nancy";

PerFilterGroupExpression group1 = new PerFilterGroupExpression();
group1.GroupOperation = PerFilterGroupOperation.Or;

PerFilterEqualToFilterExpression<string> country = new PerFilterEqualToFilterExpression<string>("Country");
country.Value = "Bulgaria";
With the demo above, you can create a filter like this:

Load and Save Filter Expressions

After the introduction above, I think you probably have had a general idea of what you can do with a Kettic filter control and all the filter expressions. In this section, we will further introduce two commonly used methods so you can save and load your filter expressions.
SaveSettings: This API can be applied to serialize the filter control expressions to Base64 encoded string.
LoadSetting: Using this method, developers can load the provided state in the filter control. Please keep in mind that the related parameter should be Base64 encoded string which represents formerly saved or existing control settings.
Here is a simple C# code demo which you copy for filter expression saving and loading testing:
protected void SaveSettings_Clicked(object sender, EventArgs e)
Session["PerFilterExpressions"] = PerFilter1.SaveSettings();
LoadSettings.Enabled = true;

protected void LoadSettings_Clicked(object sender, EventArgs e)