DetailsView.EmptyDataText 屬性

定義

取得或設定空白資料列中顯示的文字,該資料列呈現於 DetailsView 控制項繫結至不包含任何資料錄的資料來源時。

public:
 virtual property System::String ^ EmptyDataText { System::String ^ get(); void set(System::String ^ value); };
public virtual string EmptyDataText { get; set; }
member this.EmptyDataText : string with get, set
Public Overridable Property EmptyDataText As String

屬性值

String

要在空白資料列中顯示的文字。 預設為空字串 (""),表示這個屬性未設定。

範例

下列程式碼範例示範如何使用 EmptyDataText 屬性來指定要顯示在空白資料列中的文字。


<%@ 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 EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsView EmptyDataText Example</h3>
                
        <asp:detailsview id="StoresDetailView"
          datasourceid="StoresDetailsSqlDataSource"
          autogeneraterows="true" 
          EmptyDataText="No records." 
          runat="server">
               
          <emptydatarowstyle backcolor="Navy"
            forecolor="Red"/> 
                    
        </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="<%$ ConnectionStrings:NorthWindConnectionString%>"
          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 EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsView EmptyDataText Example</h3>
                
        <asp:detailsview id="StoresDetailView"
          datasourceid="StoresDetailsSqlDataSource"
          autogeneraterows="true" 
          EmptyDataText="No records." 
          runat="server">
               
          <emptydatarowstyle backcolor="Navy"
            forecolor="Red"/> 
                    
        </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="<%$ ConnectionStrings:NorthWindConnectionString%>"
          runat="server">
        </asp:sqldatasource>
            
      </form>
  </body>
</html>

備註

當系結至 控制項的資料來源不包含任何記錄時,空白的資料列會顯示在 DetailsView 控制項中。 EmptyDataText使用 屬性可指定要顯示在空白資料列中的文字。 若要控制空白資料列的樣式,請使用 EmptyDataRowStyle 屬性。 或者,您可以藉由設定 EmptyDataTemplate 屬性,而不是此屬性,定義自己的自訂使用者介面 (UI) 。

注意

如果 同時 EmptyDataText 設定 和 EmptyDataTemplate 屬性,則 EmptyDataTemplate 屬性會優先使用。

的值 EmptyDataText 會儲存在檢視狀態中。

當設定時,此屬性的值可以使用設計工具自動儲存到資源檔。 如需詳細資訊,請參閱 LocalizableAttribute 和全球化和當地語系化

適用於

另請參閱