FormView.EmptyDataText 屬性

定義

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

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>FormView EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView EmptyDataText Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        emptydatatext="No records available." 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          forecolor="White"
          font-size="14"
          font-italic="true" 
          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>
          
        <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 EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView EmptyDataText Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        emptydatatext="No records available." 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          forecolor="White"
          font-size="14"
          font-italic="true" 
          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>
          
        <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 控制項中。 EmptyDataText使用 屬性可指定要顯示在空白資料列中的文字。 若要控制空白資料列的樣式,請使用 EmptyDataRowStyle 屬性。 或者,您可以藉由設定 EmptyDataTemplate 屬性而非此屬性,定義自己的自訂使用者介面 (UI) 空白資料列。

注意

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

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

適用於

另請參閱