This documentation is archived and is not being maintained.

FieldTemplateUserControl Class

Updated: July 2008

Represents the base class for all field template controls.

Namespace:  System.Web.DynamicData
Assembly:  System.Web.DynamicData (in System.Web.DynamicData.dll)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class FieldTemplateUserControl : UserControl, 
	IBindableControl, IFieldTemplate
<asp:FieldTemplateUserControl />

ASP.NET Dynamic Data field templates are ASP.NET user controls that map data controls to data types in a data model. Field templates derive from FieldTemplateUserControl, the class that enables access to data fields, data columns, and metadata in data models. Dynamic Data projects provide field templates by default. You can modify the field templates provided by default or create custom field templates.

This class inherits from the UserControl Class.

The following code example creates a field template that displays data fields that have a many-to-one relationship and renders a HyperLink control that redirects the user to the relationship page.

ForeignKey.ascx.vb file

[Visual Basic]

Public Partial Class ForeignKeyField 
    Inherits System.Web.DynamicData.FieldTemplateUserControl 
    Protected Function GetDisplayString() As String 
    End Function 

    Public Overloads Overrides ReadOnly Property DataControl() As Control 
            Return HyperLink1 
        End Get 
    End Property 
End Class 


[Visual Basic]

<%@ Control Language="VB" CodeFile="ForeignKey.ascx.vb" Inherits="ForeignKeyField" %>

<asp:HyperLink ID="HyperLink1" runat="server"
    Text="<%# GetDisplayString() %>" />



public partial class ForeignKeyField :      
    protected string GetDisplayString() 
       Return         FormatFieldValue(ForeignKeyColumn.ParentTable.GetDisplayString(FieldValue));

    public override Control DataControl 
          return HyperLink1;



<%@ Control Language="C#" CodeFile="ForeignKey.ascx.cs" Inherits="ForeignKeyField" %>

<asp:HyperLink ID="HyperLink1" runat="server"
    Text="<%# GetDisplayString() %>" />

To compile the example code, you need the following:

  • Microsoft Visual Studio 2008 Service Pack 1 or Visual Web Developer 2008 Express Edition Service Pack 1.

  • The AdventureWorksLT sample database. For informatison about how to download and install the SQL Server sample database, see Microsoft SQL Server Product Samples: Database on the CodePlex site. Make sure that you install the correct version of the sample database for the version of SQL Server that you are running (Microsoft SQL Server 2005 or Microsoft SQL Server 2008).

  • A Dynamic Data Web site. This enables you to create a data context for the database and the class that contains the data field to customize and the methods to override. In addition, it creates the environment in which to use the page described before. For more information, see Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1




July 2008

Added topic for new class.

SP1 feature change.