BoundField.NullDisplayText Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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)

public virtual string NullDisplayText { get; set; }

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.


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.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
  <head runat="server">
    <title>BoundField NullDisplayText Example</title>
    <form id="form1" runat="server">

      <h3>BoundField NullDisplayText Example</h3>

      <asp:gridview id="DiscountsGridView" 


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



      <!-- 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%>"


.NET Framework
Available since 2.0
Return to top