The DataTypeAttribute attribute enables you to mark fields by using a type that is more specific than the database intrinsic type. The type name is selected from the DataType enumeration type. For example, a string data field that contains e-mail addresses can be specified as the EmailAddress type. This information is then accessed by the field templates to modify how the data field is processed.
You use the DataTypeAttribute attribute for the following reasons:
To provide additional type information for a data field. You do this by applying the DataTypeAttribute attribute to a data field in the data model and by specifying the additional type name from the DataType enumeration. The field template that processes the data field can access this additional metadata type information to determine how to process the field. For example, the text field template can generate hyperlinks for e-mail addresses whose intrinsic type is String.
To associate a custom field template with a data field. The specified custom field template will then be used to process the data field. This is an alternative to using the UIHintAttribute attribute.
When you apply the DataTypeAttribute attribute to a data field you must do the following:
Follow the attribute usage rules.
Implement the metadata class that contains the data fields to which you want to apply the attribute.
Issue validation errors as appropriate.
For more information, see ASP.NET Dynamic Data Guidelines.
See a run-time code example of this feature: Run.