Udostępnij za pośrednictwem


DisplayFormatAttribute.ConvertEmptyStringToNull Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates whether empty string values ("") are automatically converted to nulla null reference (Nothing in Visual Basic).

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

Syntax

'Declaration
Public Property ConvertEmptyStringToNull As Boolean
public bool ConvertEmptyStringToNull { get; set; }

Property Value

Type: System.Boolean
true if empty string values are automatically converted to nulla null reference (Nothing in Visual Basic); otherwise, false.

Examples

The following example shows how to apply the DisplayFormatAttribute attribute to a property named ListPrice that displays currency values and a property named Size that contains nulla null reference (Nothing in Visual Basic) or empty string values.

Public Class Product
  <DisplayFormat(DataFormatString:="{0:C}")> _
  Public Property ListPrice As Decimal
    'Implement Get and Set logic
  End Property

  <DisplayFormat(ConvertEmptyStringToNull:=True, NullDisplayText:="Not specified.")> _
  Public Property Size As String
    'Implement Get and Set logic
  End Property
End Class
public class Product
{
  [DisplayFormat(DataFormatString = "{0:C}")]
  public Decimal ListPrice { get; set; }

  [DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "Not specified.")]
  public string Size { get; set; }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.