FormView.EmptyDataRowStyle プロパティ

定義

TableItemStyle コントロールにバインドされたデータ ソースにレコードが格納されていない場合に表示される空のデータ行の外観を設定できる FormView オブジェクトへの参照を取得します。

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 使用して、レコードを含まないデータ ソースにコントロールをバインドしたときに FormView 表示される空のデータ行のカスタム スタイルを指定する方法を示します。


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

注釈

コントロール内の EmptyDataRowStyle 空のデータ行の外観を制御するには、 プロパティを FormView 使用します。 空のデータ行は、コントロールにバインドされているデータ ソースにレコードが含まれていない場合に表示されます。 このプロパティは読み取り専用です。ただし、返されるオブジェクトのプロパティを TableItemStyle 設定できます。 プロパティは、次のいずれかの方法を使用して宣言的に設定できます。

  • フォームの コントロールの開始タグに 属性をFormViewProperty-Subproperty配置します。ここでSubproperty、 は オブジェクトの TableItemStyle プロパティです (例: EmptyDataRowStyle-ForeColor)。

  • コントロールの <EmptyDataRowStyle> 開始タグと終了タグの間に要素を FormView 入れ子にします。

プロパティは、 形式 Property.Subproperty でプログラムで設定することもできます (例: EmptyDataRowStyle.ForeColor)。 一般的な設定には、通常、カスタムの背景色、前景色、フォント プロパティが含まれます。

適用対象

こちらもご覧ください