DisplayFormatAttribute 클래스

정의

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 하는 방법에 설명 합니다 데이터 필드에 대 한 서식을 사용자 지정 합니다. 이 예제에서는 다음 단계를 수행합니다.

  • 메타데이터 partial 클래스 및 연결된 메타데이터 클래스를 구현합니다.

  • 연결된 메타데이터 클래스에서 특성을 적용하여 다음 결과를 지정합니다 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 샘플 데이터베이스를 다운로드하고 설치하는 방법에 대한 자세한 내용은 Microsoft SQL Server 제품 샘플: GitHub의 데이터베이스를 참조하세요. 실행 중인 SQL Server 버전에 대해 올바른 버전의 샘플 데이터베이스를 설치해야 합니다.

  • 데이터 기반 웹 사이트입니다. 이렇게 하면 데이터베이스 및 사용자 지정할 데이터 필드가 포함된 클래스에 대한 데이터 컨텍스트를 만들 수 있습니다. 자세한 내용은 Walkthrough: Creating a New Dynamic Data Web Site using Scaffolding를 참조하세요.

설명

이 특성을 데이터 필드에 적용하는 경우 특성 사용에 대한 지침을 따라야 합니다. 자세한 내용은 ASP.NET 동적 데이터 지침을 참조하세요.

생성자

DisplayFormatAttribute()

DisplayFormatAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

ApplyFormatInEditMode

데이터 필드가 편집 모드에 있는 경우 DataFormatString 속성에서 지정하는 서식 문자열이 필드 값에 적용되는지 여부를 나타내는 값을 가져오거나 설정합니다.

ConvertEmptyStringToNull

데이터 소스에서 데이터 필드가 업데이트되는 경우 빈 문자열 값("")이 자동으로 null로 변환되는지 여부를 나타내는 값을 가져오거나 설정합니다.

DataFormatString

필드 값의 표시 형식을 가져오거나 설정합니다.

HtmlEncode

필드가 HTML 인코딩되는지 여부를 나타내는 값을 가져오거나 설정합니다.

NullDisplayText

필드 값이 null인 경우 해당 필드에 대해 표시되는 텍스트를 가져오거나 설정합니다.

NullDisplayTextResourceType

NullDisplayText에 대한 리소스가 포함된 Type을 가져오거나 설정합니다.

NullDisplayTextResourceTypeNullDisplayText와 함께 사용하면 GetNullDisplayText() 메서드가 지역화된 값을 반환할 수 있습니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetNullDisplayText()

NullDisplayText에 대한 UI 표시 문자열을 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_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)

적용 대상

추가 정보