Do you want to provide search in your Web page? Are you unfamiliar with data sources? Do you want to want to take advantage of a query language without having to learn the query language? You want to provide search using declarative syntax? The new QueryExtender control is your answer. This blog post provides:
· a brief overview of the QueryExtender control
· the steps required to create a search
· links to MSDN documentation that shows examples of how to use the QueryExtender control
The T:System.Web.UI.WebControls.QueryExtender class was introduced in ASP.NET 4 (Beta 1) to make filtering data in a Web page easier. You can use the QueryExtender control to provide search in a Web page without knowing too much about the underlying data source or the query language. You can use LinqDataSource or the EntityDataSource. You can use existing data controls to display the data. The QueryExtender control relies on the LINQ technology. In future versions of ASP.NET, the QueryExtender control may support other data sources or possibly any data source.
To filter data using the QueryExtender control, you can use the following steps:
1. Use Visual Studio 2010 Beta 1 to create a Web site or Web application.
2. Add or connect to a database.
3. Create a data model to the Web site or Web application.
4. Add a control to the Web page and configure the data source to work with the database table you want to use.
5. Add a QueryExtender control to the page and connect it to the data source.
The following example shows how to connect the QueryExtender to a LinqDataSource control.
6. Add the filter or filters you want to use to the QueryExtender control.
7. Add an ASP.NET control that will provide the value for the query parameter.
8. Connect the control that provides the parameter value to the filter that will use the parameter.
9. Add a data control that will display the filtered data on the page and connect the control to the data source.
The control provides the several LINQ expressions that you can use for filtering data. The expressions can be used individually or together.
The following table lists the expressions that use in the QueryExtender control to filter data.
Used to search a field or fields for string values and compares them to a specified string value.
Used to determine whether a value in a column is between specified minimum and maximum values.
Used to compare a property value of a column to a specified value.
Used to sort data by a specified column and sort direction
Used provide a custom search that can use in the QueryExtender control.
Used to filter table rows using values from a parent table in ASP.NET Dynamic Data.
Used to filter table rows using foreign key in ASP.NET Dynamic Data.
Note: If you use Visual Studio 2010 Beta1, you must modify the web.config file to include the System.Web.UI.WebControls.Expressions namespace and Assembly information. This enables you to use these Expressions.
To modify the Web.config file
1. Open the web.config file.
2. In the <Pages> tag, locate the <controls> tag and add the following code snippet:
<add tagPrefix=“asp“ namespace=“System.Web.UI.WebControls.Expressions“ assembly=“System.Web.Extensions, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31BF3856AD364E35“ />
For a complete walkthrough example of how use the QueryExtender control, see Walkthrough: Filtering Data in a Web Page Using Declarative Syntax.
For reference information, see QueryExtender Class.
For more information, see QueryExtender Web Server Control Overview.
— Philip Attipoe
ASP.NET User Education
This posting is provided “AS IS” with no warranties, and confers no rights.
Give Your Feedback on the Documentation Help us improve the developer documentation by taking the Visual Studio and .NET Framework Content Survey. This survey will give us a better understanding of the type of applications you are developing as well as how you use Help and how we can improve it. The survey takes only 10 minutes, and we appreciate your feedback.
Give Your Feedback on the Documentation
Help us improve the developer documentation by taking the Visual Studio and .NET Framework Content Survey. This survey will give us a better understanding of the type of applications you are developing as well as how you use Help and how we can improve it. The survey takes only 10 minutes, and we appreciate your feedback.