Databases Reference
In-Depth Information
Filter templates inherit from a special base class provided by Dynamic Data called
QueryableFilterUserControl . This class defines several virtual methods and properties
that child classes need to override and offers several helper methods designed to help with
implementation of concrete filter templates.
GetQueryable Method
The GetQueryable method is the heart of a filter template. It is defined as abstract in the
QueryableFilterUserControl base class and must be overridden by all filter templates to
implement the data access logic. This method receives a query object, an instance of
IQueryable , which it needs to modify based on the search value entered by the user. If the
user did not enter any search criteria for this particular column, the GetQueryable method
should return the original query. Notice how the code in Listing 5.4 checks the contents
of the TextBox control and modifies the query only if it is not empty.
OnFilterChanged Method
The OnFilterChanged method of the QueryableFilterUserControl base class notifies the
data source control responsible for executing the query and fetching rows from the data-
base that the query might have changed. The base class calls the GetQueryable method in
response to the OnFilterChanged .
In this example, the OnFilterChanged method is called from the TextBox_TextChanged
method, which handles the OnTextChanged event of the TextBox control. This ensures that
any change to the search value entered in the text box is detected during the post-back,
and the GetQueryable method is invoked to apply the filter.
DefaultValue Property
The DefaultValue property provides the initial filter value. When instantiated as part of
the List page template, which is discussed in Chapter 6, “Page Templates,” filters can be
initialized by passing column names and values through the page request URL. Although
not required for new filter templates, supporting this functionality is important to make
them behave consistently with the built-in templates provided by Dynamic Data project
templates.
Dynamic LINQ Queries
Most filter templates, such as the Text.ascx in this example, can be reused for any column
of a matching type. Dynamic filter templates, such as this, cannot hardcode the column
name in the query. Instead, use the column metadata, available through the Column prop-
erty of the QueryableFilterUserControl base class, to get the column name and build the
query dynamically:
 
 
Search WWH ::




Custom Search