FormView.EmptyDataTemplate 属性
定义
public:
virtual property System::Web::UI::ITemplate ^ EmptyDataTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.FormView))]
public virtual System.Web.UI.ITemplate EmptyDataTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.FormView))>]
member this.EmptyDataTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property EmptyDataTemplate As ITemplate
属性值
一个 ITemplate,包含空数据行的自定义内容。A ITemplate that contains the custom content for the empty data row. 默认值为 null,表示未设置此属性。The default value is null, which indicates that this property is not set.
- 属性
示例
下面的示例演示如何为在 FormView 控件绑定到不包含任何记录的数据源时所显示的空数据行定义自定义模板。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#" %>
<!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>FormView EmptyDataTemplate Example</title>
</head>
<body>
<form id="form1" 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") %> <%# Eval("LastName") %></h3>
<%# Eval("Title") %>
</td>
</tr>
</table>
</itemtemplate>
<emptydatatemplate>
<table>
<tr>
<td>
<asp:image id="NoDataImage"
imageurl="~/Images/NoDataImage.jpg"
alternatetext="No image"
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>
<%@ Page language="VB" %>
<!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>FormView EmptyDataTemplate Example</title>
</head>
<body>
<form id="form1" 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") %> <%# Eval("LastName") %></h3>
<%# Eval("Title") %>
</td>
</tr>
</table>
</itemtemplate>
<emptydatatemplate>
<table>
<tr>
<td>
<asp:image id="NoDataImage"
imageurl="~/Images/NoDataImage.jpg"
alternatetext="No image"
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>
注解
FormView当绑定到控件的数据源不包含任何记录时,将在控件中显示空数据行。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. 您可以使用属性为空的数据行定义您自己的自定义用户界面 (UI) EmptyDataTemplate 。You can define your own custom user interface (UI) for the empty data row by using the EmptyDataTemplate property. 若要为空数据行指定自定义模板,请先在 <EmptyDataTemplate> 控件的开始和结束标记之间放置标记 FormView 。To specify a custom template for the empty data row, first place <EmptyDataTemplate> tags between the opening and closing tags of the FormView control. 然后,你可以在开始标记和结束标记之间列出模板的内容 <EmptyDataTemplate> 。You can then list the contents of the template between the opening and closing <EmptyDataTemplate> tags. 若要控制空数据行的样式,请使用 EmptyDataRowStyle 属性。To control the style of the empty data row, use the EmptyDataRowStyle property. 或者,您可以通过设置 EmptyDataText 属性而不是此属性,对空数据行使用内置 UI。Alternatively, you can use the built-in UI for the empty data row by setting the EmptyDataText property instead of this property.
备注
如果同时 EmptyDataText 设置了和 EmptyDataTemplate 属性,则 EmptyDataTemplate 属性优先。If both the EmptyDataText and EmptyDataTemplate properties are set, the EmptyDataTemplate property takes precedence.