DetailsView.EmptyDataTemplate Свойство

Определение

Возвращает или задает определенное пользователем содержимое для пустой строки данных, когда элемент управления DetailsView привязан к источнику данных, не имеющему записей.

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

Значение свойства

ITemplate

ITemplate, содержащий настраиваемое содержимое для пустой строки данных. Значение по умолчанию равно null и показывает, что значение свойства не задано.

Атрибуты

Примеры

В следующем примере кода показано, как использовать EmptyDataTemplate свойство для создания настраиваемой пустой строки данных.


<%@ 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>

Комментарии

Пустая строка данных отображается в элементе DetailsView управления, когда источник данных, привязанный к элементу управления, не содержит записей. Вы можете определить собственный пользовательский интерфейс для пустой строки данных с помощью EmptyDataTemplate свойства. Чтобы указать пользовательский шаблон для пустой строки, сначала поместите <EmptyDataTemplate> теги между открывающим и закрывающим тегами DetailsView элемента управления. Затем можно вывести список содержимого шаблона между открывающим и закрывающим <EmptyDataTemplate> тегами. Чтобы управлять стилем пустой строки данных, используйте EmptyDataRowStyle свойство. Кроме того, можно использовать встроенный пользовательский интерфейс для пустой строки данных, задав EmptyDataText свойство вместо этого свойства.

Примечание

Если заданы оба EmptyDataText EmptyDataTemplate свойства, EmptyDataTemplate свойство имеет приоритет.

Применяется к

См. также раздел