Export (0) Print
Expand All

DisplayAttribute Class

Specifies localizable strings for entity types and members that are used in the user interface.

System.Object
  System.Attribute
    System.ComponentModel.DataAnnotations.DisplayAttribute

Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)

[AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter, AllowMultiple = false)]
public sealed class DisplayAttribute : Attribute

The DisplayAttribute type exposes the following members.

  NameDescription
Public methodDisplayAttributeInitializes a new instance of the DisplayAttribute class.
Top

  NameDescription
Public propertyAutoGenerateFieldGets or sets a value that indicates whether the field is automatically displayed in the user interface.
Public propertyAutoGenerateFilterGets or sets a value that indicates whether filtering is automatically displayed for this field.
Public propertyDescriptionGets or sets either a resource name or non-localized text, such as a tool tip, that is displayed to users to help them understand a member.
Public propertyGroupNameGets or sets either a resource name or non-localized text that is displayed to users when grouping fields in the user interface.
Public propertyNameGets or sets either a resource name or non-localized text that is used as a member label for elements that are bound to the member.
Public propertyOrderGets or sets a value that indicates the order in which columns are sorted.
Public propertyPromptGets or sets either a resource name or non-localized text, such as a watermark, that suggests a user action for an element that is bound to the member.
Public propertyResourceTypeGets or sets the type that contains the resources for other localizable property values.
Public propertyShortNameGets or sets either a resource name or non-localized text that is used as the column label for an element that is bound to the member.
Top

  NameDescription
Public methodEqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetAutoGenerateFieldRetrieves the value of the AutoGenerateField property.
Public methodGetAutoGenerateFilterRetrieves the value of the AutoGenerateFilter property.
Public methodGetDescriptionRetrieves the localized or non-localized value of the Description property.
Public methodGetGroupNameRetrieves the localized or non-localized value of the GroupName property.
Public methodGetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public methodGetNameRetrieves the localized or non-localized value of the Name property.
Public methodGetOrderRetrieves the value of the Order property.
Public methodGetPromptRetrieves the localized or non-localized value of the Prompt property.
Public methodGetShortNameRetrieves the localized or non-localized value of the ShortName property.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodMatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

You apply the DisplayAttribute attribute to a property to specify values that are used to enhance the display of the property values. When a data field is bound to a property, controls, such as the DataGrid control, automatically incorporate values from the DisplayAttribute attribute. The DisplayAttribute class provides the following properties for customizing string values that are displayed for the data field:

  • Name - The full name to use as a label for the field, such as "Social Security Number".

  • ShortName - A compressed or abbreviated version of the name to use as a label for the field, such as "SSN". This value is used by the DataGrid control.

  • Description - The text that appears in the user interface to provide more information about the field. The text can be used as a tool tip.

  • Prompt - The text that is intended as a water mark for the field to suggest a user action.

  • GroupName - A name that is used when grouping data.

  • Order - A number that indicates the position of a user-interface element that represents the field, relative to other fields. This value is used by the DataGrid control to establish the column ordering.

  • AutoGenerateField - A value that indicates whether the field is included in the automatic generation of user-interface elements such as columns. This value is used by the DataGrid control.

  • AutoGenerateFilter - A value that indicates whether a user-interface element that is automatically generated for the field should include filtering capabilities.

The following example shows how to use the DisplayAttribute attribute to set both localized and non-localized display values. A property named EmailAddress includes non-localized display values and a property named LastName includes localized display values that are retrieved from a resource type named DisplayResources.


public class Customer
{
  [Display(Name = "Email Address", 
     Description = "An email address is needed to provide notifications about the order.")]
  public string EmailAddress { get; set; }

  [Display(ResourceType=typeof(DisplayResources), Name="LName", Description="LNameDescription")]
  public string LastName { get; set; }
}


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft