Databases Reference
In-Depth Information
<label>City:</label>
<asp:DynamicControl runat=”server” DataField=”City” />
<label>State:</label>
<asp:DynamicControl runat=”server” DataField=”Region” />
<label>Zip:</label>
<asp:DynamicControl runat=”server” DataField=”PostalCode” />
</fieldset>
</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>
As discussed in Chapter 1, “Getting Started,” the code-behind of pages that use dynamic
controls need to associate the databound control, such as the
FormView
in this example,
with the
MetaTable
instance describing the entity class. The
MetaTable
is typically
retrieved using the
MetaModel
instance created in the
Global.asax
and exposed by the
DefaultModel
static property, as shown in Listing 4.2.
LISTING 4.2
Customer Information Page (Code-Behind)
using System;
using System.Web.DynamicData;
namespace WebApplication.Samples.Ch04.ReadOnlyTemplate
{
public partial class SamplePage : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
MetaTable table = Global.DefaultModel.GetTable(“Customers”);
this.form.SetMetaTable(table);
}
}
}