Export (0) Print
Expand All

ASP.NET Dynamic Data Default Field Templates

Visual Studio 2008

Updated: July 2008

Field templates are ASP.NET user controls that map the data control field to data types in a data model. These controls are derived from the FieldTemplateUserControl class, which enables access to data fields, database columns, and metadata. Dynamic Data uses field templates to automatically display data based on the database schema and data type, and to enable users to edit and insert data in a data model with minimal or no code. Dynamic data provides default field templates when you create a Dynamic Data Web application.

ASP.NET Dynamic Data determines the data type of the data in the data model and uses the appropriate default or custom field template to render the data in a data control. The field template that is rendered depends both on the data type, the UIHint or defined DataTypeAttribute and whether the data control is in display, edit, or insert mode. When you create a Dynamic Data project in Visual Studio 2008, the default field templates are created in the DynamicData/FieldTemplates directory. 

The following table describes the default field templates in ASP.NET Dynamic Data projects.

Default field template

Description

Boolean.ascx

Displays Boolean data type. Renders a CheckBox control. The CheckBox control is disabled and cannot be changed.

Boolean_Edit.ascx

Enables users to edit Boolean values. Renders a CheckBox control.

Children.ascx

Displays fields that have a one-to-many relationship and redirects the user to the relationship page. Renders a HyperLink control.

DateTime.ascx

Displays DateTime data type as text. Renders as a literal.

DateTime_Edit.ascx

Renders a TextBox control. If the field in the database cannot be null or if a required attribute is added to the data model, this control also renders a RequiredFieldValidator control. The DateTime_Edit.ascxfield template provides a System.Web.DynamicData.DynamicValidator control that handles any exceptions that are thrown from the data model. Supports the Regex class.

Decimal_Edit.ascx

Renders a TextBox control. Also renders a CompareValidator control that verifies that the input can be converted to a Decimal data type. If the field in the database cannot be null or if a required attribute is added to the data model, this control also renders a RequiredFieldValidator control. If the field has a range attribute, the field also renders a RangeValidator control. The Decimal_Edit.ascx field template provides a System.Web.DynamicData.DynamicValidator control that handles any exceptions that are thrown from the data model. This field template supports the Regex class.

ForeignKey.ascx

Displays fields that have a many-to-one relationship. Renders a HyperLink control that redirects the user to the relationship page.

ForeignKey_Edit.ascx

Used to edit fields that have a many-to-one relationship. Renders a DropDownList control that enables users to select foreign keys in the data model.

Integer_Edit.ascx

Renders a TextBox control and a CompareValidator that verifies that the input in the text box can be converted to an integer. If the field in the database cannot be null, or if a required attribute is added to the data model, this control alsorenders a RequiredFieldValidator control. If the field in the model has a range attribute, the field also renders a RangeValidator control. Integer_Edit.ascx provides a System.Web.DynamicData.DynamicValidator control that handles any exceptions that are thrown from the data model. Supports the Regex class.

Text.ascx

Displays String, Decimal, Double, and Int32 including other integer types such as byte, short and long. Renders as a literal.

Text_Edit.ascx

Renders a TextBox control. The TextMode property of the text box is set to SingleLine. If the field in the database cannot be null, or if a required attribute is added to the data model, Text_Edit.ascx alsorenders a RequiredFieldValidator control. If the field in the database has a length associated with it, the MaxLength property of the text box control is enforced. If there is a RegularExpression attribute on the data model, the default field template also renders a RegularExpressionValidator control. Text_Edit.ascxprovides a System.Web.DynamicData.DynamicValidator control to handle any exceptions that are thrown from the data model.

Multiline_Edit.ascx

Used for database fields that are marked as text blocks. For example, in SQL Server, Multiline_Edit.ascx maps to the TEXT, NTEXT, VARCHAR(MAX), NVARCHAR(MAX) data types.

Renders a TextBox control. The TextMode property of the text box is set to MultiLine. If the field in the database cannot be null or if a required attribute is added to the data model, MultiLine_Edit.ascx also renders a RequiredFieldValidator control. If a RegularExpression attribute is added to the data model, the data field also renders a RegularExpressionValidator control. MultiLine_Edit.ascxprovidesa System.Web.DynamicData.DynamicValidator control that handles any exceptions that are thrown from the data model.

Customizing the Default Templates

You can customize the default field templates to change their display, edit, and insert behavior. The modification affects the whole Web site. For example, you can change the background and foreground colors of the DateTime_Edit.ascx by modifying BackColor and ForeColor properties of the text box that renders the field template. This modification can be done by defining the BackColor and ForeColor properties in a .css file. For more information, see How to: Customize ASP.NET Dynamic Data Default Field Templates.

Date

History

Reason

July 2008

Added topic.

SP1 feature change.

Community Additions

ADD
Show:
© 2014 Microsoft