[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Enables data from a data source to be filtered without an explicit Where clause in the data source.
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web.Extensions (in System.Web.Extensions.dll)
Visual Basic (Declaration)
<ToolboxBitmapAttribute(GetType(QueryExtender), "QueryExtender.bmp")> _
Public Class QueryExtender _
Inherits Control
Dim instance As QueryExtender
[ToolboxBitmapAttribute(typeof(QueryExtender), "QueryExtender.bmp")]
public class QueryExtender : Control
[ToolboxBitmapAttribute(typeof(QueryExtender), L"QueryExtender.bmp")]
public ref class QueryExtender : public Control
[<ToolboxBitmapAttribute(typeof(QueryExtender), "QueryExtender.bmp")>]
type QueryExtender =
class
inherit Control
end
In this topic:
Introduction
The QueryExtender control is used to create filters for data that is retrieved from a data source, without using an explicit Where clause in the data source. The QueryExtender control can be used to specify filtering by using declarative syntax.
Background
Filtering excludes data from a data source by displaying only the records that meet specified criteria. Filtering enables you to present different views of the data that is in a data set without affecting the data in the data set.
Filtering typically requires that you create a Where clause to apply to the command that queries the data source. However, the Where property of the data source control might not expose the full functionality that is available. For example, the ability to query a table using declarative syntax in not available in the LinqDataSource control.
To expose the full functionality that is available in LINQ and to make filtering data easier, ASP.NET provides the QueryExtender control. The QueryExtender control has the following benefits:
It provides a richer filtering experience than writing a Where clause. For example, you can search a Products table for Boolean values by using the PropertyExpression filter without writing a query.
It lets you specify filters by using the same syntax for the LinqDataSource and EntityDataSource controls and for any other data source controls that you might use.
It can be used with LinqDataSource control, with a EntityDataSource control, or with third-party data sources.
Filter Options
The QueryExtender control supports a variety of options that you can use to filter data. The control lets you search strings, search numeric values in a specified range, and compare a property value in a table to a specified value. The control also lets you sort the data and provide custom queries.
These options are provided as LINQ expressions in the QueryExtender control. The QueryExtender control also supports expressions that are specific to ASP.NET Dynamic Data applications.
The following table lists the options that you can use to filter data in the QueryExtender control.
You can use these QueryExtender options individually or you can combine them to provide complex filtering in a Web page. For more information, see QueryExtender Web Server Control Overview. Walkthrough: Filtering Data in a Web Page Using Declarative Syntax
Tasks
The following table lists tasks that show how to use the QueryExtender control to filter data.
Declarative Syntax
<asp:QueryExtender
EnableViewState="True|False"
ID="string"
OnDataBinding="DataBiding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="UnLoad event hadler"
Runat="server"
TargetControlID="string"
Visible="True|False"
>
<asp:ControlFilterExpression
ControlD="string"
Column="string">
</asp:ControlFilterExpression>
<asp:DynamicFilterExpression
ControlD="string"
</asp:DynamicFilterExpression>
<asp:CustomExpression="string"
OnQuerying="OnQerying event handler">
</asp:CustomExpression>
<asp:OrderByExpression="string"
DataField="string"
Direction="string">
<asp:ThenByExpression
DataField="string"
Direction="string"
</asp:ThenBy>
</asp:OrderByExpression>
<asp:PropertyExpression="string">
<!-- child controls -->
</asp:PropertyExpression
>
<asp:RangeExpression="integer"
Datafield="string"
MaxType="Exclusive|Inclusive|None"
MinType="Exclusive|Inclusive|None">
<!--child controls-->
</asp:RangeExpression>
<asp:SearchExpression="string"
ComparisonType="CurrentCulture|CurrentCultureIgnoreCase|
InavariantCulture|InvariantCultureIgnoreCase|
Ordinal|OrdinalIgnoreCase"
DataField="string"
SearchType="Contains|EndsWith|StartsWith">
<!--child controls-->
</asp:SearchExpression>
</asp:QueryExtender>
The following example shows how to use the QueryExtender control to provide a search function in a Web page. The QueryExtender control uses the text that is entered in the TextBoxSearch control to search for contents in the ProductName and Supplier.CompanyName columns of a Products table in the data that is returned from the LinqDataSource control. The SearchExpression object is used to perform the search. The DataFields property specifies the data fields to search. The SearchType property specifies the type of search to perform. The ControlParameter element specifies the control that contains the text to use for the search. This code example is part of a larger example that is provided in Walkthrough: Filtering Data in a Web Page Using Declarative Syntax.
<asp:LinqDataSource ID="dataSource" runat="server"
TableName="Products">
</asp:LinqDataSource>
<asp:QueryExtender TargetControlID="dataSource" runat="server">
<asp:SearchExpression DataFields="ProductName, Supplier.CompanyName"
SearchType="StartsWith">
<asp:ControlParameter ControlID="TextBoxSearch" />
</asp:SearchExpression>
</asp:QueryExtender>
The following example shows how to use the QueryExtender control to search a Web page for values in a specified range. The QueryExtender control uses the values that are entered in the TextBoxFrom and TextBoxTo controls to search for values in the ProductName and Supplier.CompanyName columns of a Products table in the data that is returned from the LinqDataSource control. The ControlParameter element specifies the text box controls that contain the minimum and maximum values to use for searching the range. The MinType and MaxType properties specify that the minimum and maximum values must be included in the data that is returned. This code example is part of a larger example provided in Walkthrough: Filtering Data in a Web Page Using Declarative Syntax.
<asp:LinqDataSource ID="dataSource" runat="server"
TableName="Products">
</asp:LinqDataSource>
<asp:QueryExtender TargetControlID="dataSource" runat="server">
<asp:RangeExpression DataField="UnitPrice" MinType="Inclusive"
MaxType="Inclusive">
<asp:ControlParameter ControlID="TextBoxFrom" />
<asp:ControlParameter ControlID="TexBoxTo" />
</asp:RangeExpression>
</asp:QueryExtender>
System..::.Object
System.Web.UI..::.Control
System.Web.UI.WebControls..::.QueryExtender
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 4
Reference
Other Resources