Databases Reference
In-Depth Information
all that is required is to specify the appropriate value in the
SortExpression
property of
the
UnleashedField
(this property is actually inherited directly from the
DataControlField
base class). The following markup snippet illustrates how this was done in the last sample
page:
<unl:UnleashedField DataField=”Product” HeaderText=”Product” UIHint=”Parent”
DisplayField=”ProductName”
SortExpression=”Product.ProductName
”/>
With a LINQ-enabled data source, the
SortExpression
can traverse related entities
through the navigation properties. To allow sorting the list of order items by the product
name, you simply specify
SortExpression
of the first column as
Product
.
ProductName
,
where Product is the name of the navigation property of the Order_Detail entity. What
the
SortExpression
does when the user clicks the Product column in the
GridView
control on the sample page is very similar the following LINQ query. Of course, setting
the
SortExpression
does not require any custom code and is much more compact:
using (var context = new NorthwindEntities())
{
IQueryable<Order_Detail> query =
from item in context.Order_Details
orderby item.Product.ProductName
select item;
}
Many similarities exist between the
DynamicControl
and field templates on one side and
the
DynamicFilter
control and filter templates on the other. As you recall from a discus-
sion in Chapter 10, “Building Custom Forms,” the
DynamicControl
allows you to assemble
custom entity forms from field templates based on the type of entity properties. If you
need a specific field template for a given property, such as the
MultilineText
template,
you can specify its name in the
UIHint
attribute of the
DynamicControl
:
<asp:DynamicControl runat=”server” DataField=”Address”
UIHint=”MultilineText”
/>
If you want to provide additional information to the field template, you can do so by
specifying custom attributes directly in markup. The
DynamicControl
automatically assigns
the custom attribute values, such as the Columns attribute shown next, to the matching
public properties of the field template:
<asp:DynamicControl runat=”server” DataField=”Address”
Columns=”65”
/>
When it comes to dynamic filters, the
DynamicFilter
control also supports the ability to
specify the template name explicitly by setting its
FilterUIHint
attribute in markup. You