Edit

Share via


DisplayFormatAttribute.DataFormatString Property

Definition

Gets or sets the display format for the field value.

public:
 property System::String ^ DataFormatString { System::String ^ get(); void set(System::String ^ value); };
public string DataFormatString { get; set; }
public string? DataFormatString { get; set; }
member this.DataFormatString : string with get, set
Public Property DataFormatString As String

Property Value

A formatting string that specifies the display format for the value of the data field. The default is an empty string (""), which indicates that no special formatting is applied to the field value.

Examples

The following examples show how to use the DataFormatString property to set the display format of data fields. The first example sets the display format for a currency type data field. The second example sets the display format for a date type data field.

// Display currency data field in the format $1,345.50.
[DisplayFormat(DataFormatString="{0:C}")]
public object StandardCost;
' 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 11/12/08.
// Also, apply format in edit mode.
[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:d}")]
public object SellStartDate;
' 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

Remarks

Use the DataFormatString property to specify a custom display format for the values that are displayed in the DynamicField object. If the DataFormatString property is not set, the field's value is displayed without any special formatting. For more information, see Formatting Types.

Note

When the DynamicField.HtmlEncode property is true, the value of the field is HTML encoded to its string representation before the formatting string is applied. For some objects, such as dates, you might want to control how the object is displayed with a formatting string. In those cases, you must set the DynamicField.HtmlEncode property to false.

By default, the formatting string is applied to the field value only when the data-bound control that contains the DynamicField object is in read-only mode. To apply the formatting string to field values when they are in edit mode, set the ApplyFormatInEditMode property to true.

The formatting string can be any literal string and usually includes a placeholder for the field's value. For example, in the formatting string "Item Value: {0}", the field's value is substituted for the {0} placeholder when the string is displayed in the DynamicField object. The remainder of the formatting string is displayed as literal text.

Note

If the formatting string does not include a placeholder, the field's value from the data source is not included in the final display text.

Applies to

See also