BANGALORE, INDIA: ASP.NET has been evolving with each new version along with a number of out-of-band releases such as the Ajax Control Toolkit, ASP.NET MVC and Dynamic Data.
ASP.NET 4.0 will see a consolidation of all of these technologies under a common umbrella along with new enhancements to each of them. However, the core ASP.NET stack too gets some new features. The one that we'll delve into this month is a new control called QueryExtender.
How it helps
One of the most common tasks that developers do on Web pages is connect to data and display them on the page. They also give ways for the user to filter it based on different criteria. Normally this is done by writing a dynamic SQL query that changes depending on the filter parameters being sent. For each new parameter, the developer has to create a new set of steps to parse and add the filter to the SQL query.
The QueryExtender control does away with all this repetitive and cumbersome coding. Instead by simply dropping a control and configuring it, you can get all the power of dynamic filtering for your data. This article shows you how you can do this.
Creating a filter page
To work with the new ASP.NET 4.0 you need to install Visual Studio 2010 Beta 1. This also installs the .NET 4.0 Beta 1. Once installed, fire up VS 2010 and create a new ASP.NET web site. Connect to your database using LINQ or Entity Framework and add tables you wish to query to your project. Once that is done, open up Web.config and add the following line to it in the <pages><controls> section:
<add tagPrefix="asp" namespace="System.Web.UI.WebControls.Expressions" assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Note: This needs to be done only for the current beta. For later versions, it will be done automatically.
Now you are ready to start using the QueryExtender control. First off, create a normal ASPX page that uses the LinqDataSource or the EntityDataSource control to connect to your respective data model. Attach a GridView to display results and test it out without filters.