Export (0) Print
Expand All

DetailsView.EmptyDataText Property

Gets or sets the text to display in the empty data row rendered when a DetailsView 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; }
<asp:DetailsView EmptyDataText="String" />

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 DetailsView 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.

NoteNote:

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

The value of EmptyDataText is stored in view state.

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 code 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" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>DetailsView EmptyDataText Example</h3>

        <asp:detailsview id="StoresDetailView"
          datasourceid="StoresDetailsSqlDataSource"
          autogeneraterows="true" 
          EmptyDataText="No records." 
          runat="server">

          <emptydatarowstyle backcolor="Navy"
            forecolor="Red"/> 

        </asp:detailsview>

        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Pubs sample database.                        -->

        <!-- The select query of the following SqlDataSource     -->
        <!-- control has been intentionally set to return no     --> 
        <!-- results to demonstrate the empty data row.          -->      
        <asp:sqldatasource id="StoresDetailsSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores] WHERE [state]='FL'"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
          runat="server">
        </asp:sqldatasource>

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, 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

Community Additions

ADD
Show:
© 2014 Microsoft