DisplayFormatAttribute.NullDisplayText 属性
本文内容
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置字段值为 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 值,必须将 属性设置为 ConvertEmptyStringToNulltrue
。
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
UWP | 10.0 |