Export (0) Print
Expand All

FormView.EmptyDataTemplate Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the user-defined content for the empty data row rendered when a FormView 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)

[TemplateContainerAttribute(typeof(FormView))] 
public virtual ITemplate EmptyDataTemplate { get; set; }
/** @property */
public ITemplate get_EmptyDataTemplate ()

/** @property */
public void set_EmptyDataTemplate (ITemplate value)

public function get EmptyDataTemplate () : ITemplate

public function set EmptyDataTemplate (value : ITemplate)

Property Value

A System.Web.UI.ITemplate that contains the custom content for the empty data row. The default value is a null reference (Nothing in Visual Basic), which indicates that this property is not set.

The empty data row is displayed in a FormView 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 empty data row, first place <EmptyDataTemplate> tags between the opening and closing tags of the FormView 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 example demonstrates how to define a custom template for the empty data row displayed when a FormView control is bound to a data source that does not contain any records.


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

<html>
  <body>
    <form runat="server">
        
      <h3>FormView EmptyDataTemplate Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID" 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          height="100"/> 
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %>&nbsp;<%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
        <emptydatatemplate>
          <table>
            <tr>
              <td>
                <asp:image id="NoDataImage"
                  imageurl="~/Images/NoDataImage.jpg" 
                  runat="server"/>
              </td>
              <td>
                No records available.
              </td>
            </tr>
          </table>
        </emptydatatemplate>
          
        <pagersettings position="Bottom"
          mode="NextPrevious"/> 
                  
      </asp:formview>
          
      <!-- 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 select query for the following SqlDataSource     -->
      <!-- control is intentionally set to return no results    -->
      <!-- to demonstrate the empty data row.                   --> 
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees] Where [EmployeeID]=1000"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>


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

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft