Databases Reference
In-Depth Information
LISTING 5.2
Simple Search Page (Code-Behind)
using System;
using System.Linq;
using DataModel;
namespace WebApplication.Samples.Ch05.LinqFilter
{
public partial class SamplePage : System.Web.UI.Page
{
protected void Find_Click(object sender, EventArgs e)
{
using (NorthwindEntities context = new NorthwindEntities())
{
IQueryable<Customer> customers = context.Customers;
if (this.cityFilter.Text.Length > 0)
{
customers = customers.Where(c => c.City == this.cityFilter.Text);
}
if (this.titleFilter.Text.Length > 0)
{
customers = customers.Where(c=>c.ContactTitle==this.titleFilter.Text);
}
this.gridView.DataSource = customers.ToArray();
this.gridView.DataBind();
}
}
}
}
To create a filter template for the City column, you need to extract both the markup and
the code into a new user control and save it in the DynamicData\Filters folder of the web
project. Note that the markup and code-behind for the ContactTitle column is nearly
identical to that of the City column. The filter template created here works for both of
these columns. Listings 5.3 and 5.4 show its markup and code-behind respectively.
LISTING 5.3
Text F ilter Template (Mar kup)
<%@ Control Language=”C#” CodeBehind=”Text.ascx.cs”
Inherits=”WebApplication.DynamicData.Filters.TextFilter” %>
<asp:TextBox runat=”server” ID=”textBox” OnTextChanged=”TextBox_TextChanged” />
 
Search WWH ::




Custom Search