Databases Reference
In-Depth Information
LISTING 4.11
Default Entity Template (Code-Behind)
using System;
using System.Collections.Generic;
using System.Web.DynamicData;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication.DynamicData.EntityTemplates
{
public partial class DefaultEntityTemplate : EntityTemplateUserControl
{
private MetaColumn currentColumn;
protected override void OnLoad(EventArgs e)
{
IEnumerable<MetaColumn> scaffoldColumns = this.Table.GetScaffoldColumns(
this.Mode, this.ContainerType);
foreach (MetaColumn column in scaffoldColumns)
{
this.currentColumn = column;
NamingContainer container = new NamingContainer();
this.entityTemplate.ItemTemplate.InstantiateIn(container);
this.entityTemplate.Controls.Add(container);
}
}
protected void Label_Init(object sender, EventArgs e)
{
((Label)sender).Text = this.currentColumn.DisplayName;
}
protected void DynamicControl_Init(object sender, EventArgs e)
{
((DynamicControl)sender).DataField = this.currentColumn.Name;
}
}
}
NOTE
Note that NamingContainer is a custom control that inherits directly from the built-in
Control and implements the INamingContainer marker interface. The ASP.NET
runtime relies on this interface to determine naming boundaries and generate control
IDs unique across the entire page.
Search WWH ::




Custom Search