共用方式為


QueryExtender Web Server Control Overview

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 control can be used to filter data in markup of a Web page 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 varying views of the data that is in a dataset without affecting the data in the dataset.

Filtering typically requires you to create Where clauses to apply to the command that queries the data source. However, the Where property of the LinqDataSource control does not expose the full functionality that is available in LINQ.

To make filtering data easier, ASP.NET provides the QueryExtender control, which can be used with a data source to filter data by using declarative syntax. Using the QueryExtender control has the following benefits:

  • Provides richer expressions for filtering than writing a Where clause.

  • Provides a common query language for the LinqDataSource and EntityDataSource control. For example, if you use the QueryExtender with these data source controls, you can provide searching capability in a Web page without writing a model-specific Where clause or eSQL statement.

  • Can be used with LinqDataSource or EntityDataSource controls, or with third-party data sources.

  • Supports a variety of filtering options that can be used individually or together.

Filter Options

The QueryExtender control supports a variety of options that you can use to filter data. The control supports searching strings, searching values between a specified range, comparing a property value in a table to a specified value, sorting, and 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.

SearchExpession

The SearchExpression class searches a field or fields for string values and compares them to a specified string value. The expression can perform a "starts with", "contains", or "ends with" search. For example, you can enter text into a text box control and use the expression to search for that text in columns that are returned from a data source control.

Note

Case sensitivity in the search expression depends on the LINQ provider that you specify in the QueryExtender control.

RangeExpression

The RangeExpression class is like the SearchExpression class, but uses a pair of values to define a range. The expression determines whether a value in a column is between specified minimum and maximum values. For example, you can search the unit price column in a table for values between $10 and $100.

PropertyExpression

The PropertyExpression class compares a property value of a column to a specified value. For example, you can compare a Boolean value to the value in the discontinued column of a Products table in a database.

OrderByExpression

The OrderByExpression class lets you sort data by a specified column and sort direction.

CustomExpression

The CustomExpression class enables you to provide a custom LINQ expression that can use in the QueryExtender control.

DynamicFilterExpression

The DynamicFilterExpression class is supported only in ASP.NET Dynamic Data Web sites. For more information, see ASP.NET Dynamic Data.

ControlFilterExpression

The ControlFilterExpression class is supported only in ASP.NET Dynamic Data Web sites. For more information, see ASP.NET Dynamic Data.

Code Examples

For an example of how to use the QueryExtender control, see The Entity Framework and ASP.NET – Getting Started Part 3.

Class Reference

The following table lists the key classes that relate to the QueryExtender control.

Expression

Description

QueryExtender

Represents the main class for the control.

CustomExpression

Specifies a user-defined expression for a data source. The custom expression can be in a function and can be called from page markup.

OrderByExpression

Applies a sort expression to an IQueryable data source object.

PropertyExpression

Creates a Where clause from specified parameters in a WhereParameters collection.

RangeExpression

Determines whether a value is greater or less than a specified value, or if a value is between two specified values.

SearchExpression

Searches a field or fields for string values and compares them to a specified string value.

ThenByExpressions

Applies a sort expression to an IQueryable data source object after an OrderByExpression expression is applied.

DynamicFilterExpression

Builds a database query using the specified filter control.

ControlFilterExpression

Builds a database query using the data key that is selected in a source data-bound control.

See Also

Reference

QueryExtender

QueryableDataSource