DataType 列舉


代表與資料欄位和參數關聯的資料類型列舉。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 14

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

Currency 6

表示貨幣值。Represents a currency value.

Custom 0

表示自訂資料型別。Represents a custom data type.

Date 2

表示日期值。Represents a date value.

DateTime 1

表示時間的瞬間,以一天的日期和時間表示。Represents an instant in time, expressed as a date and time of day.

Duration 4

表示物件存在的持續時間。Represents a continuous time during which an object exists.

EmailAddress 10

表示電子郵件地址。Represents an email address.

Html 8

表示 HTML 檔。Represents an HTML file.

ImageUrl 13

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

MultilineText 9

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

Password 11

表示密碼值。Represent a password value.

PhoneNumber 5

表示電話號碼值。Represents a phone number value.

PostalCode 15

表示郵遞區號。Represents a postal code.

Text 7

表示顯示的文字。Represents text that is displayed.

Time 3

表示時間值。Represents a time value.

Upload 16

表示檔案上傳資料型別。Represents file upload data type.

Url 12

表示 URL 值。Represents a URL value.


下列範例會使用 DataTypeAttribute 屬性來自訂 AdventureWorksLT 資料庫中 customer 資料表的 EmailAddress 資料欄位顯示。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 相關聯的中繼資料類別中的列舉值,將屬性套用至 EmailAddress 資料欄位。Applies the DataTypeAttribute attribute to the EmailAddress data field by specifying the EmailAddress enumerated value in the associated metadata class. 這表示已自訂電子郵件地址顯示的 [文字檔] 欄位範本。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;

public partial class Customer

public class CustomerMetaData

    // Add type information.
    public object EmailAddress;

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 產品範例: databaseFor 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. 如需詳細資訊,請參閱 逐步解說:使用樣板建立新的動態資料網站For more information, see Walkthrough: Creating a New Dynamic Data Web Site Using Scaffolding.

如需欄位範本用來自訂 EmailAddress 資料欄位顯示的完整程式碼範例,請參閱 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. 例如,包含電子郵件地址的字串資料欄位可以使用列舉值來進行屬性 EmailAddressFor 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.