DisplayFormatAttribute.DataFormatString 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定欄位值的顯示格式。
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
屬性值
一個格式化字串,用來指定資料欄位值的顯示格式。 預設為空字串(“”),表示欄位值未套用特殊格式。
範例
以下範例說明如何利用該 DataFormatString 屬性設定資料欄位的顯示格式。 第一個範例設定了貨幣類型資料欄位的顯示格式。 第二個範例設定日期類型資料欄位的顯示格式。
// 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
備註
使用該 DataFormatString 屬性來指定物件中顯示 DynamicField 值的自訂顯示格式。 若未設定屬性 DataFormatString ,欄位值會顯示,且不會有特殊格式。 如需詳細資訊,請參閱格式類型。
備註
當屬性 DynamicField.HtmlEncode 為 true時,欄位的值會先以 HTML 編碼成其字串表示,然後再套用格式字串。 對於某些物件,例如日期,你可能想用格式字串來控制物件的顯示方式。 在這些情況下,你必須將屬性設 DynamicField.HtmlEncode 為 false。
預設情況下,格式字串僅在包含 DynamicField 該物件的資料綁定控制項處於唯讀模式時,才套用到欄位值。 若要將格式字串套用到欄位值,當欄位值處於編輯模式時,請將屬性設定 ApplyFormatInEditMode 為 true。
格式字串可以是任何字串,通常會包含欄位值的佔位符。 例如,在格式字串「Item Value: {0}」中,當字串在物件中DynamicField顯示時,欄位的值會被{0}取代佔位符。 格式字串的其餘部分則以文字顯示。
備註
如果格式字串不包含佔位符,該欄位來自資料來源的值不會包含在最終顯示文字中。