Databases Reference
In-Depth Information
Metadata information, readily available in Dynamic Data web applications, dramatically
lowers the amount of plumbing code developers have to write when working with user
controls, enables effective use of smaller user controls, and takes code reuse to an unprece-
dented new level.
Read-Only Templates
By convention, field templates are located in the DynamicData\FieldTemplates folder of
the Dynamic Data web application projects and websites. A single instance of a field
template provides user interface for one particular field value. Consider Listing 3.1, which
shows markup file of the DateTime field template.
LISTING 3.1 DateTime Field Template (Markup)
<%@ Control Language=”C#” CodeBehind=”DateTime.ascx.cs”
Inherits=”WebApplication.DynamicData.FieldTemplates.DateTimeField” %>
<asp:Literal runat=”server” ID=”literal” Text=”<%# FieldValueString %>” />
This is a read-only field template, the simplest type of field template. It relies on ASP.NET
data binding syntax <%# %> to display the field value in a single Literal control. Listing
3.2 shows the code-behind of the DateTime field template. You can see that it inherits
from the FieldTemplateUserControl , a special base class provided for field templates by
Dynamic Data. This class defines the FieldValueString property to which the Literal
control is bound.
LISTING 3.2 DateTime Field Template (Code-behind)
using System.Web.DynamicData;
using System.Web.UI;
namespace WebApplication.DynamicData.FieldTemplates
{
public partial class DateTimeField : FieldTemplateUserControl
{
public override Control DataControl
{
get { return this.literal; }
}
}
}
 
 
Search WWH ::




Custom Search