DetailsView.EmptyDataRowStyle 屬性

定義

取得 TableItemStyle 物件的參考,可以讓您設定當繫結至 DetailsView 控制項的資料來源不含任何資料錄時,顯示之空白資料列的外觀。

public:
 property System::Web::UI::WebControls::TableItemStyle ^ EmptyDataRowStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TableItemStyle EmptyDataRowStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.EmptyDataRowStyle : System.Web.UI.WebControls.TableItemStyle
Public ReadOnly Property EmptyDataRowStyle As TableItemStyle

屬性值

TableItemStyle 的參考,可以讓您設定空白資料列的外觀。

屬性

範例

下列程式碼範例示範如何使用 EmptyDataRowStyle 屬性來指定空白資料列的字型和樣式設定。


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

備註

EmptyDataRowStyle使用 屬性來控制 控制項中 DetailsView 空白資料列的外觀。 系結至 控制項的資料來源不包含任何記錄時,會顯示空白資料列。 此屬性是唯讀的;不過,您可以設定它所傳回之 TableItemStyle 物件的屬性。 屬性可以宣告方式在 表單 Property-Subproperty 中設定,其中 Subproperty 是物件的屬性 TableItemStyle (例如, EmptyDataRowStyle-ForeColor) 。 屬性也可以在表單 Property.Subproperty 中以程式設計方式設定,例如 () EmptyDataRowStyle.ForeColor 。 一般設定通常包括自訂背景色彩、前景色彩和字型屬性。

適用於

另請參閱