Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DetailsView.EmptyDataTemplate Property

Gets or sets the user-defined content for 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)

[PersistenceModeAttribute(PersistenceMode.InnerProperty)]
[TemplateContainerAttribute(typeof(DetailsView))]
[BrowsableAttribute(false)]
public virtual ITemplate EmptyDataTemplate { get; set; }
<asp:DetailsView>
	<EmptyDataTemplate>ITemplate</EmptyDataTemplate>
</asp:DetailsView>

Property Value

Type: System.Web.UI.ITemplate
A System.Web.UI.ITemplate that contains the custom content for the empty data row. The default value is null, 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. You can define your own custom user interface (UI) for the empty data row by using the EmptyDataTemplate property. To specify a custom template for the null row, first place <EmptyDataTemplate> tags between the opening and closing tags of the DetailsView control. You can then list the contents of the template between the opening and closing <EmptyDataTemplate> tags. To control the style of the empty data row, use the EmptyDataRowStyle property. Alternatively, you can use the built-in UI for the empty data row by setting the EmptyDataText property instead of this property.

NoteNote:

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

The following code example demonstrates how to use the EmptyDataTemplate property to create a custom 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 EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>DetailsView EmptyDataTemplate Example</h3>

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

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

          <emptydatatemplate>

            <table width="100%">

              <tr>
                <td>
                  <asp:Image id="NoRecordsImage"
                    AlternateText='No records' 
                    imageurl="~\images\NoRecords.jpg"
                    runat="server"/> 
                </td>
                <td>
                  <asp:Label id="NoRecordsMessageLabel"
                    forecolor="Red"
                    text="No Records."
                    runat="server"/> 
                </td>
              </tr>

            </table>

          </emptydatatemplate> 

        </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="server=localhost;database=pubs;integrated security=SSPI"
          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:
© 2015 Microsoft