DisplayFormatAttribute.ConvertEmptyStringToNull Property

 

Gets or sets a value that indicates whether empty string values ("") are automatically converted to null when the data field is updated in the data source.

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

public bool ConvertEmptyStringToNull { get; set; }

Property Value

Type: System.Boolean

true if empty string values are automatically converted to null; otherwise, false. The default is true.

Users might enter an empty string for a field value. Use the ConvertEmptyStringToNull property to specify whether an empty string value is automatically converted to null when the data field is updated in the database.

System_CAPS_noteNote

By default, a DynamicField object displays null values as empty strings. To display a different value, set the NullDisplayText property.

The following example shows how to use the ConvertEmptyStringToNull to enable the conversion of empty string values to 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;

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 3.0
Return to top
Show: