i

ASP.Net A Complete Guide

Variety of filter options provided by QueryExtender

SearchExpression : It provides the text based search. It performs a text-search in given field, searches a field or fields for string values, and compares them to a given string value. The expression can perform the search using "starts with", "contains", or "ends with".

Example:

<asp:QueryExtender ID="ExampleOfQueryExtender" runat="server" TargetControlID="ldsOfLinqDataSource">

 <asp:SearchExpression DataFields="FirstName" SearchType="Contains">

  <asp:ControlParameter ControlID="TextBoxName" />

 </asp:SearchExpression>

</asp:QueryExtender>

 

RangeExpression: it indicates that the value falls between the minimum and maximum ranges.

Example:

<asp:QueryExtender ID="ExampleOfQueryExtender" runat="server" TargetControlID="ldsOfLinqDataSource">

 <asp:RangeExpression DataField="EmployeeId" MaxType="Inclusive" MinType="Inclusive">

   <asp:ControlParameter ControlID="TextBoxFrom" />

   <asp:ControlParameter ControlID="TextBoxTo" />

 </asp:RangeExpression>

</asp:QueryExtender>

OrderByExpression: This allows us to sort data as per the sort direction.

Example:

<asp:QueryExtender ID="ExampleOfQueryExtender" runat="server" TargetControlID="ldsOfLinqDataSource">

 <asp:OrderByExpression DataField="Salary" Direction="Descending">

        <asp:ThenBy DataField="EmployeeId" Direction="Ascending" />

 </asp:OrderByExpression>

</asp:QueryExtender>

 

PropertyExpression: This allows us to compare the value of a property with the specified value.

Example:

<asp:QueryExtender ID="ExampleOfQueryExtender" runat="server" TargetControlID="ldsOfLinqDataSource">

 <asp:PropertyExpression>

        <asp:ControlParameter ControlID="IsActive" Name="Active" />

 </asp:PropertyExpression>

</asp:QueryExtender>

 

ControlFilterExpression: This helps us to filter the field value of a web control page EX- TextBox, DropDownList.

Example:

<asp:QueryExtender ID="ExampleOfQueryExtender" runat="server" TargetControlID="ldsOfLinqDataSource">

 <asp:ControlFilterExpression  ControlD="FirstNameId"  Column="FirstName">  

 </asp:ControlFilterExpression

</asp:QueryExtender>

 

CustomExpression and MethodExpression - They both are used to perform the same action. It allows us to write our own filtering logic.

Example:

 

<asp:QueryExtender ID="ExampleOfQueryExtender" runat="server" TargetControlID="ldsOfLinqDataSource">

 <asp:CustomExpression OnQuerying="FilterEmployee"></asp:CustomExpression>

</asp:QueryExtender>

 

Custom logic of “FilterEmployee”

protected void FilterEmployee(object sender, CustomExpressionEventArgs e)

{

    e.Query = from E in e.Query.Cast<Product>()

              where E.ListPrice >= 6600

              select E;

}