DisplayFormatAttribute 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
ASP.NET Dynamic Data에서 데이터 필드를 표시하고 서식을 지정하는 방법을 지정합니다.
public ref class DisplayFormatAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)]
public class DisplayFormatAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)>]
type DisplayFormatAttribute = class
inherit Attribute
Public Class DisplayFormatAttribute
Inherits Attribute
- 상속
- 특성
예제
다음 예제에서는 데이터 필드의 DisplayFormatAttribute 서식을 사용자 지정하는 방법을 보여 있습니다. 이 예제에서는 다음 단계를 수행합니다.
메타데이터 부분 클래스 및 연결된 메타데이터 클래스를 구현합니다.
연결된 메타데이터 클래스에서 특성을 적용하여 다음 결과를 지정합니다 DisplayFormatAttribute .
- 데이터 필드가 비어 있으면 "Null]" 텍스트를 표시합니다.
- 통화 데이터를 로캘별 통화 형식으로 표시합니다.
- 날짜 정보를 짧은 형식(mm/dd/yy)으로 표시합니다. 이 형식은 편집 모드에서도 적용됩니다.
using System;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;
[MetadataType(typeof(ProductMetaData))]
public partial class Product
{
}
public class ProductMetaData
{
// Applying DisplayFormatAttribute
// Display the text [Null] when the data field is empty.
// Also, convert empty string to null for storing.
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Null]")]
public object Size;
// Display currency data field in the format $1,345.50.
[DisplayFormat(DataFormatString="{0:C}")]
public object StandardCost;
// Display date data field in the short format 11/12/08.
// Also, apply format in edit mode.
[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]
public object SellStartDate;
}
Imports System.Web.DynamicData
Imports System.ComponentModel.DataAnnotations
<MetadataType(GetType(ProductMetaData))> _
Partial Public Class Product
End Class
Public Class ProductMetaData
' Applying DisplayFormatAttribute
' Display the text [Null] when the data field is empty.
' Also, convert empty string to null for storing.
<DisplayFormat(ConvertEmptyStringToNull:=True, NullDisplayText:="[Null]")> _
Public Size As Object
' Display currency data field in the format such as $1,345.50.
<DisplayFormat(DataFormatString:="{0:C}")> _
Public StandardCost As Object
' Display date data field in the short format such as 11/12/08.
' Also, apply format in edit mode.
<DisplayFormat(ApplyFormatInEditMode:=True, DataFormatString:="{0:d}")> _
Public SellStartDate As Object
End Class
예제를 컴파일하려면 다음이 필요합니다.
- Visual Studio 2010 이상의 모든 버전.
- AdventureWorksLT 샘플 데이터베이스입니다. SQL Server 샘플 데이터베이스를 다운로드하고 설치하는 방법에 대한 자세한 내용은 GitHub Microsoft SQL Server 제품 샘플: Database를 참조하세요. 실행 중인 SQL Server 버전에 대해 올바른 버전의 샘플 데이터베이스를 설치해야 합니다.
- 데이터 기반 웹 사이트입니다. 이렇게 하면 데이터베이스 및 사용자 지정할 데이터 필드가 포함된 클래스에 대한 데이터 컨텍스트를 만들 수 있습니다. 자세한 내용은
Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding를 참조하세요.
설명
데이터 필드에 이 특성을 적용하는 경우 특성 사용에 대한 지침을 따라야 합니다.
생성자
| Name | Description |
|---|---|
| DisplayFormatAttribute() |
DisplayFormatAttribute 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| ApplyFormatInEditMode |
데이터 필드가 편집 모드에 있을 때 속성에 DataFormatString 지정된 서식 문자열이 필드 값에 적용되는지 여부를 나타내는 값을 가져오거나 설정합니다. |
| ConvertEmptyStringToNull |
데이터 원본에서 데이터 필드가 업데이트되는 경우 빈 문자열 값("")이 자동으로 변환 |
| DataFormatString |
필드 값의 표시 형식을 가져오거나 설정합니다. |
| HtmlEncode |
필드를 HTML로 인코딩해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다. |
| NullDisplayText |
필드 값 |
| NullDisplayTextResourceType |
에 대한 NullDisplayText리소스가 Type 포함된 항목을 가져오거나 설정합니다. 와 함께 NullDisplayText사용하면 NullDisplayTextResourceType 메서드가 GetNullDisplayText() 지역화된 값을 반환할 수 있습니다. |
| TypeId |
파생 클래스에서 구현되는 경우 이 Attribute대한 고유 식별자를 가져옵니다. (다음에서 상속됨 Attribute) |
메서드
| Name | Description |
|---|---|
| Equals(Object) |
이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다. (다음에서 상속됨 Attribute) |
| GetHashCode() |
이 인스턴스의 해시 코드를 반환합니다. (다음에서 상속됨 Attribute) |
| GetNullDisplayText() |
에 대한 UI 표시 문자열을 반환합니다 NullDisplayText. |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| IsDefaultAttribute() |
파생 클래스에서 재정의되는 경우 이 인스턴스의 값이 파생 클래스의 기본값인지 여부를 나타냅니다. (다음에서 상속됨 Attribute) |
| Match(Object) |
파생 클래스에서 재정의되는 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다. (다음에서 상속됨 Attribute) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
명시적 인터페이스 구현
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다. (다음에서 상속됨 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다. (다음에서 상속됨 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1). (다음에서 상속됨 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
개체에 의해 노출되는 속성 및 메서드에 대한 액세스를 제공합니다. (다음에서 상속됨 Attribute) |