EmptyDataText Property
Collapse the table of content
Expand the table of content

GridView.EmptyDataText Property


Gets or sets the text to display in the empty data row rendered when a GridView control is bound to a data source that does not contain any records.

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

public virtual string EmptyDataText { get; set; }

Property Value

Type: System.String

The text to display in the empty data row. The default is an empty string (""), which indicates that this property is not set.

The empty data row is displayed in a GridView control when the data source that is bound to the control does not contain any records. Use the EmptyDataText property to specify the text to display in the empty data row. To control the style of the empty data row, use the EmptyDataRowStyle property. Alternatively, you can define your own custom user interface (UI) for the empty data row by setting the EmptyDataTemplate property instead of this property.


If both the EmptyDataText and EmptyDataTemplate properties are set, the EmptyDataTemplate property takes precedence.

The value of this property, when set, can be saved automatically to a resource file by using a designer tool. For more information, see LocalizableAttribute and ASP.NET Globalization and Localization.

The following example demonstrates how to use the EmptyDataText property to specify the text to display in the empty data row.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>GridView EmptyDataText Example</title>
    <form id="form1" runat="server">

      <h3>GridView EmptyDataText Example</h3>

      <asp:gridview id="CustomersGridView" 
        emptydatatext="No data in the data source."

        <emptydatarowstyle backcolor="LightBlue"


      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file. The following query        -->
      <!-- returns an empty data source to demonstrate the      -->
      <!-- empty row.                                           -->
      <asp:sqldatasource id="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"


.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft