DataType DataType DataType DataType Enum

定义

表示与数据字段和参数关联的数据类型的枚举。Represents an enumeration of the data types associated with data fields and parameters.

public enum class DataType
public enum DataType
type DataType = 
Public Enum DataType
继承

字段

CreditCard CreditCard CreditCard CreditCard 14

表示信用卡号码。Represents a credit card number.

Currency Currency Currency Currency 6

表示货币值。Represents a currency value.

Custom Custom Custom Custom 0

表示自定义的数据类型。Represents a custom data type.

Date Date Date Date 2

表示日期值。Represents a date value.

DateTime DateTime DateTime DateTime 1

表示某个具体时间,以日期和当天的时间表示。Represents an instant in time, expressed as a date and time of day.

Duration Duration Duration Duration 4

表示对象存在的一段连续时间。Represents a continuous time during which an object exists.

EmailAddress EmailAddress EmailAddress EmailAddress 10

表示电子邮件地址。Represents an email address.

Html Html Html Html 8

表示一个 HTML 文件。Represents an HTML file.

ImageUrl ImageUrl ImageUrl ImageUrl 13

表示图像的 URL。Represents a URL to an image.

MultilineText MultilineText MultilineText MultilineText 9

表示多行文本。Represents multi-line text.

Password Password Password Password 11

表示密码值。Represent a password value.

PhoneNumber PhoneNumber PhoneNumber PhoneNumber 5

表示电话号码值。Represents a phone number value.

PostalCode PostalCode PostalCode PostalCode 15

表示邮政代码。Represents a postal code.

Text Text Text Text 7

表示所显示的文本。Represents text that is displayed.

Time Time Time Time 3

表示时间值。Represents a time value.

Upload Upload Upload Upload 16

表示文件上载数据类型。Represents file upload data type.

Url Url Url Url 12

表示 URL 值。Represents a URL value.

示例

下面的示例使用DataTypeAttribute属性来自定义电子邮件地址的 AdventureWorksLT 数据库中的客户表的数据字段的显示。The following example uses the DataTypeAttribute attribute to customize the display of EmailAddress data field of the customer table in the AdventureWorksLT database. 电子邮件地址从内部数据类型显示为超链接,而不是 ASP.NET 动态数据将具有推断的简单文本。The email addresses are shown as hyperlinks instead of the simple text that ASP.NET Dynamic Data would have inferred from the intrinsic data type.

示例代码中:The example code:

  • 实现相关的表的元数据分部类和关联的元数据类。Implements a metadata partial class for the related table and the associated metadata class.

  • 适用DataTypeAttribute通过指定属性的电子邮件地址数据字段EmailAddress枚举值关联的元数据类中。Applies the DataTypeAttribute attribute to the EmailAddress data field by specifying the EmailAddress enumerated value in the associated metadata class. 这向 Text.ascx 字段模板表明,电子邮件地址显示自定义。This indicates to the Text.ascx field template that the email address display is customized.

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;

}

Imports System
Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations

<MetadataType(GetType(CustomerMetadata))> _
Partial Public Class Customer


End Class

Public Class CustomerMetadata

    ' Add type information.
    <DataType(DataType.EmailAddress)> _
    Public EmailAddress As Object

End Class

若要编译此代码示例,需要满足以下要求:To compile the example code, you need the following:

  • Visual Studio 2008 Service Pack 1 或 Visual Developer 2008 Express Edition Service Pack 1。Visual Studio 2008 Service Pack 1 or Visual Developer 2008 Express Edition Service Pack 1.

  • AdventureWorksLT 示例数据库。The AdventureWorksLT sample database. 有关如何下载和安装 SQL Server 示例数据库的信息,请参阅Microsoft SQL Server 产品示例:数据库For information about how to download and install the SQL Server sample database, see Microsoft SQL Server Product Samples: Database. 请确保安装版本的 SQL Server 正在 (SQL Server 2005 或 SQL Server 2008) 的示例数据库的正确版本。Make sure that you install the correct version of the sample database for the version of SQL Server that you are running (SQL Server 2005 or 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. 有关详细信息,请参见演练:创建新的动态数据 Web 站点使用基架For more information, see Walkthrough: Creating a New Dynamic Data Web Site Using Scaffolding.

字段模板使用自定义电子邮件地址的数据字段的显示完整的代码示例,请参阅DataTypeAttribute属性。For the complete code example that the field template uses to customize the display of the EmailAddress data fields, see the DataTypeAttribute attribute.

注解

此枚举用于指定要将数据列或参数与相关联的数据类型。This enumeration is used to specify the type of data to associate with a data column or a parameter. 您使用DataTypeAttribute属性类,以指定的数据类型你想要将与数据字段或参数相关联。You use the DataTypeAttribute attribute class to specify the data type you want to associate with the data field or parameter. 此枚举中选择的数据类型。You select the data type from this enumeration.

DataTypeAttribute属性允许您通过使用比数据库内部类型更具体的类型标记的字段。The DataTypeAttribute attribute lets you mark fields by using a type that is more specific than the database intrinsic types. 例如,包含电子邮件地址的字符串数据字段也可以使用特性化EmailAddress枚举值。For example, a string data field that contains email addresses can be attributed with the EmailAddress enumerated value. 此信息的字段模板可以访问和修改数据字段的处理方式。This information can be accessed by the field templates and modify how the data field is processed.

适用于

另请参阅