DetailsView.EmptyDataTemplate Właściwość
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Pobiera lub ustawia zawartość zdefiniowaną przez użytkownika dla pustego wiersza danych renderowanego, gdy kontrolka DetailsView jest powiązana ze źródłem danych, które nie zawiera żadnych rekordów.
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.DetailsView))]
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.DetailsView))>]
member this.EmptyDataTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property EmptyDataTemplate As ITemplate
Wartość właściwości
Element ITemplate zawierający zawartość niestandardową dla pustego wiersza danych. Wartość domyślna to null, która wskazuje, że ta właściwość nie jest ustawiona.
- Atrybuty
Przykłady
W poniższym przykładzie kodu pokazano, jak za pomocą EmptyDataTemplate właściwości utworzyć niestandardowy pusty wiersz danych.
<%@ 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>
<%@ 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>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>
Uwagi
Pusty wiersz danych jest wyświetlany w kontrolce, gdy źródło danych powiązane z kontrolką DetailsView nie zawiera żadnych rekordów. Możesz zdefiniować własny niestandardowy interfejs użytkownika dla pustego wiersza danych przy użyciu EmptyDataTemplate właściwości . Aby określić szablon niestandardowy dla wiersza o wartości null, należy najpierw umieścić <EmptyDataTemplate> tagi między tagami otwierania i zamykania kontrolki DetailsView . Następnie można wyświetlić listę zawartości szablonu między tagami otwierania i zamykania <EmptyDataTemplate> . Aby kontrolować styl pustego wiersza danych, użyj EmptyDataRowStyle właściwości . Alternatywnie możesz użyć wbudowanego interfejsu użytkownika dla pustego wiersza danych, ustawiając EmptyDataText właściwość zamiast tej właściwości.
Uwaga
EmptyDataText Jeśli właściwości i EmptyDataTemplate są ustawione, EmptyDataTemplate właściwość ma pierwszeństwo.