Databases Reference
In-Depth Information
FIGURE 1.16
Filter templates in a Dynamic Data project.
It comes as no surprise that filter templates are also a special kind of ASP.NET user controls
located in the DynamicData/Filters folder of the web application project. In this example,
there is a filter based on the Category column of the Products table. This column is a
foreign key pointing to the Categories table of the Northwind database. The default filter
provided by Dynamic Data for a foreign key column is a drop-down list that displays
all records from the table it references. The markup from ForeignKey.ascx is shown in
Listing 1.17.
LISTING 1.17
ForeignKey Filter Template (Markup)
<%@ Control Language=”C#” CodeBehind=”ForeignKey.ascx.cs”
Inherits=”WebApplication.DynamicData.Filters.ForeignKeyFilter” %>
<asp:DropDownList runat=”server” ID=”dropDownList” AutoPostBack=”True”
OnSelectedIndexChanged=”DropDownList_SelectedIndexChanged”>
<asp:ListItem Text=”All” Value=”” />
</asp:DropDownList>
This looks deceptively simple, and as you would expect, the heavy lifting is done in code,
by dynamically loading the list of database records to populate the drop-down list and
constructing a lambda expression that represents an additional where clause for the LINQ
query. You will not be looking at the code-behind of the filter templates just yet. Filtering
functionality is by far the most complex code in Dynamic Data; the detailed discussion of
this topic is found in Chapter 5, “Filter Templates.”
The QueryExtender control supports multiple filter expressions. If you need to allow users
to search products by Supplier, you can simply add a new DynamicFilter control to the
form and a new DynamicFilterExpression to the QueryExtender . However, if you need to
have dynamic filters for all supported columns in the table, you can do it more quickly
with the help of the QueryableFilterRepeater control, as shown in Listing 1.18.
 
Search WWH ::




Custom Search