DisplayFormatAttribute.NullDisplayText 屬性

定義

取得或設定欄位值為 null 時為欄位顯示的文字。

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

屬性值

文字,會在欄位值為 null 時為欄位顯示。 預設為空字串 (""),表示這個屬性未設定。

範例

下列範例示範如何使用 NullDisplayText 來定義數據欄位為 null時所顯示的 標題。

// 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 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

備註

有時候,數據欄位的值會儲存為來源中的 Null 值。 您可以藉由設定 NullDisplayText 屬性,指定要針對具有 Null 值的數據欄位顯示自訂文字。 如果未設定此屬性,null 域值會顯示為空字串, (“”) 。

注意

若要將空字串網域值轉換成 Null 值,您必須將 ConvertEmptyStringToNull 屬性設定為 true

適用於

另請參閱