Represents an enumeration of data types associated with data fields and parameters.
public enum DataType
Inherit
Object ⟶ \longrightarrow⟶ ValueType ⟶ \longrightarrow ⟶ Enum ⟶ \longrightarrow ⟶ DataType
Field
Field | length | Description |
---|---|---|
Credit Card | 14 | Represents the credit card number. |
Currency | 6 | Represents monetary value. |
Custom | 0 | Represents a custom data type. |
Date | 2 | Represents the date value. |
DateTime | 1 | Indicates a specific time, expressed in terms of date and time of day. |
Duration | 4 | Represents a continuous period of time that the object exists. |
EmailAddress | 10 | Represents an email address. |
Html | 8 | Represents an HTML file. |
ImageUrl | 13 | Represents the URL of the image. |
MultilineText | 9 | Represents multiple lines of text. |
Password | 11 | Represents the password value. |
PhoneNumber | 5 | Represents the phone number value. |
PostalCode | 15 | Represents the postal code. |
Text | 7 | Represents the displayed text. |
Time | 3 | Represents the time value. |
Upload | 16 | Indicates the file upload data type. |
Url | 12 | Represents the URL value. |
Example
The following example uses DataTypeAttribute
the attribute to customize AdventureWorksLT
the database customer
tables EmailAddress
display data fields. The e-mail address is displayed as a hyperlink, rather than as simple text inferred from internal data types by ASP.NET dynamic data.
Sample code:
- Metadata partial class that implements related tables and associated metadata classes.
DataTypeAttribute
ByEmailAddress
specify enumeration value associated metadata category, the characteristic is applied toEmailAddress
the data field. This will display the "body" field template for the email address display.
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
// Add type information.
[DataType(DataType.EmailAddress)]
public object EmailAddress;
}
To compile the code example, the following components are required:
- Visual Studio 2008 Service Pack 1 or Visual Developer 2008 Express Edition Service Pack 1.
- AdventureWorksLT sample database. For information on how to download and install the SQL Server sample database, see Microsoft SQL Server Product Sample: Database. Make sure to install the correct sample database version for the version of SQL Server running (SQL Server 2005 or SQL Server 2008).
- A website with dynamic data. This allows you to create a data context for the database, and create a class that contains the data fields you want to customize, and the methods to override. In addition, it creates an environment for using the previously mentioned pages. For more information, see Walkthrough: Use scaffolding to create a new dynamic data website.
For custom field templates for EmailAddress
a complete code sample data fields, see DataTypeAttribute
property.
annotation
This enumeration is used to specify the data type to be associated with the data column or parameter. Use DataTypeAttribute
attribute class to specify the data type associated with the data fields or parameters. Select the data type in this enumeration.
DataTypeAttribute
The feature allows you to mark fields with more specific types than the internal types of the database. For example, a string data field containing an email address can be attributed using enumerated values EmailAddress
. This information can be accessed by field templates and can modify the way the data fields are processed.