Databases Reference
In-Depth Information
Extending DynamicField to Support Control Parameters
The updated UnleashedControl allows you to take advantage of metadata-driven control
parameters in pages that rely on entity templates and template controls , such as the
FormView or the ListView . However, you still have the same limitation in pages that rely
on field controls , such as the GridView or the DetailsView . Listing 11.6 shows an example
of such a page.
LISTING 11.6 Page with GridView and DynamicField Controls (Markup)
<%@ Page Language=”C#”
MasterPageFile=”~/Site.master” CodeBehind=”SamplePage.aspx.cs”
Inherits=”WebApplication.Samples.Ch11.DynamicField.SamplePage” %>
<asp:Content ContentPlaceHolderID=”main” runat=”server”>
<asp:GridView ID=”gridView” runat=”server” DataSourceID=”dataSource”
AutoGenerateEditButton=”true” AutoGenerateColumns=”false”
DataKeyNames=”EmployeeID”>
<Columns>
<asp:DynamicField DataField=”FirstName” />
<asp:DynamicField DataField=”LastName” />
<asp:DynamicField DataField=”Address” />
<asp:DynamicField DataField=”City” />
<asp:DynamicField DataField=”Region” />
<asp:DynamicField DataField=”Country” />
<asp:DynamicField DataField=”PostalCode” />
</Columns>
</asp:GridView>
<asp:EntityDataSource ID=”dataSource” runat=”server”
ConnectionString=”name=NorthwindEntities” EntitySetName=”Employees”
DefaultContainerName=”NorthwindEntities” EnableUpdate=”True” />
</asp:Content>
If you build and run this page, notice that the Address text box appears with its default
size, ignoring the Columns parameter specified in the metadata to make it wider. This is
because the DynamicField instances used to define grid columns create DynamicControl
objects, which do not support control parameters defined in metadata. You can solve
this problem by extending the DynamicField class to override its CreateDynamicControl
method and return a new UnleashedControl instead of the built-in DynamicControl .
Listing 11.7 shows how the UnleashedField class (available the sample solution) does
that.
 
Search WWH ::




Custom Search