Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
BoundField Class
 NullDisplayText Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
BoundField..::.NullDisplayText Property

Updated: November 2007

Gets or sets the caption displayed for a field when the field's value is null.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Visual Basic (Declaration)
Public Overridable Property NullDisplayText As String
Visual Basic (Usage)
Dim instance As BoundField
Dim value As String

value = instance.NullDisplayText

instance.NullDisplayText = value
C#
public virtual string NullDisplayText { get; set; }
Visual C++
public:
virtual property String^ NullDisplayText {
    String^ get ();
    void set (String^ value);
}
J#
/** @property */
public String get_NullDisplayText()
/** @property */
public  void set_NullDisplayText(String value)
JScript
public function get NullDisplayText () : String
public function set NullDisplayText (value : String)

Property Value

Type: System..::.String

The caption displayed for a field when the field's value is null. The default is an empty string (""), which indicates that this property is not set.

Sometimes a field's value is stored as null in the data source. You can specify a custom caption to display for fields that have a null value by setting the NullDisplayText property. If this property is not set, null field values are displayed as empty strings (""). When a record is being updated or inserted in a data-bound control, if the user enters the value specified by this property (other than an empty string) for a field in a data-bound control, that value is automatically converted to null in the data source.

Note:

To convert an empty string field value to a null value, set the ConvertEmptyStringToNull property to true.

The following code example demonstrates how to use the NullDisplayText property to specify a custom caption to display for null field values.

Visual Basic
<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>BoundField NullDisplayText Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>BoundField NullDisplayText Example</h3>

      <asp:gridview id="DiscountsGridView" 
        datasourceid="DiscountsSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">

        <columns>

          <asp:boundfield datafield="discounttype"
            nulldisplaytext="No Data"
            headertext="Discount Type"/>

          <asp:boundfield datafield="stor_id"
            nulldisplaytext="No Data"
            headertext="Store ID"/> 

          <asp:boundfield datafield="lowqty"
            nulldisplaytext="No Data"
            headertext="Low Quantity"/>

          <asp:boundfield datafield="highqty"
            nulldisplaytext="No Data"
            headertext="High Quantity"/>

          <asp:boundfield datafield="discount"
            nulldisplaytext="No Data"
            dataformatstring="{0:F4}%" 
            itemstyle-horizontalalign="Right" 
            headertext="Discount"/>     

        </columns>

      </asp:gridview>

      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="DiscountsSqlDataSource"  
        selectcommand="SELECT [discounttype], [stor_id], [lowqty], [highqty], [discount] FROM [discounts]"
        connectionstring="<%$ ConnectionStrings:PubsConnectionString%>"
        runat="server">
      </asp:sqldatasource>

    </form>
  </body>
</html>


C#
<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
  <head runat="server">
    <title>BoundField NullDisplayText Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>BoundField NullDisplayText Example</h3>

      <asp:gridview id="DiscountsGridView" 
        datasourceid="DiscountsSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">

        <columns>

          <asp:boundfield datafield="discounttype"
            nulldisplaytext="No Data"
            headertext="Discount Type"/>

          <asp:boundfield datafield="stor_id"
            nulldisplaytext="No Data"
            headertext="Store ID"/> 

          <asp:boundfield datafield="lowqty"
            nulldisplaytext="No Data"
            headertext="Low Quantity"/>

          <asp:boundfield datafield="highqty"
            nulldisplaytext="No Data"
            headertext="High Quantity"/>

          <asp:boundfield datafield="discount"
            nulldisplaytext="No Data"
            dataformatstring="{0:F4}%" 
            itemstyle-horizontalalign="Right" 
            headertext="Discount"/>     

        </columns>

      </asp:gridview>

      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="DiscountsSqlDataSource"  
        selectcommand="SELECT [discounttype], [stor_id], [lowqty], [highqty], [discount] FROM [discounts]"
        connectionstring="<%$ ConnectionStrings:PubsConnectionString%>"
        runat="server">
      </asp:sqldatasource>

    </form>
  </body>
</html>


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker