Databases Reference
In-Depth Information
LISTING 4.4
Customer Entity Template (Code-Behind)
using System.Web.DynamicData;
namespace WebApplication.DynamicData.EntityTemplates
{
public partial class CustomerEntityTemplate :
EntityTemplateUserControl
{
}
}
Having defined the entity template, you can modify the Customer Information page to
take advantage of it by replacing the entire contents of the
FormView
with a
DynamicEntity
control, as shown in Listing 4.5.
LISTING 4.5
Customer Information Page with Entity Template (Markup)
<%@ Page Language=”C#”
MasterPageFile=”~/Site.master” CodeBehind=”SamplePage.aspx.cs”
Inherits=”WebApplication.Samples.Ch04.ReadOnlyTemplate.SamplePage” %>
<asp:Content runat=”server” ContentPlaceHolderID=”main”>
<asp:ValidationSummary runat=”server” />
<asp:FormView ID=”form” runat=”server” DataSourceID=”dataSource”>
<ItemTemplate>
<asp:DynamicEntity runat=”server” />
</ItemTemplate>
</asp:FormView>
<asp:EntityDataSource ID=”dataSource” runat=”server”
ConnectionString=”name=NorthwindEntities” AutoGenerateWhereClause=”true”
DefaultContainerName=”NorthwindEntities” EntitySetName=”Customers”>
<WhereParameters>
<asp:QueryStringParameter QueryStringField=”ID” Name=”CustomerID” />
</WhereParameters>
</asp:EntityDataSource>
</asp:Content>
DynamicEntity
is a new control defined in the
System.Web.DynamicData
namespace.
At run time, it automatically determines the
MetaTable
associated with its parent
FormView
control and locates a template with a matching name in the
DynamicData\EntityTemplates
folder of the web application. If the matching entity
template exists,
DynamicEntity
loads and includes it the web page, which in this example
makes it look identical to the one shown in Figure 4.1.