FormView.EmptyDataRowStyle Proprietà

Definizione

Ottiene un riferimento all'oggetto TableItemStyle che consente di impostare l'aspetto della riga di dati vuota visualizzata quando l'origine dati associata a un controllo FormView non contiene record.

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

Valore della proprietà

Riferimento all'oggetto TableItemStyle che consente di impostare l'aspetto della riga di dati vuota.

Attributi

Esempio

Nell'esempio seguente viene illustrato come usare la EmptyDataRowStyle proprietà per specificare uno stile personalizzato per la riga di dati vuota visualizzata quando un FormView controllo è associato a un'origine dati che non contiene record.


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

Commenti

Utilizzare la EmptyDataRowStyle proprietà per controllare l'aspetto della riga di dati vuota in un FormView controllo. La riga di dati vuota viene visualizzata quando l'origine dati associata al controllo non contiene record. Questa proprietà è di sola lettura; tuttavia, è possibile impostare le proprietà dell'oggetto TableItemStyle restituito. Le proprietà possono essere impostate in modo dichiarativo usando uno dei metodi seguenti:

  • Inserire un attributo nel tag di apertura del FormView controllo nel formato Property-Subproperty, dove Subproperty è una proprietà dell'oggetto TableItemStyle , ad esempio EmptyDataRowStyle-ForeColor.

  • Annidare un <EmptyDataRowStyle> elemento tra i tag di apertura e chiusura del FormView controllo.

Le proprietà possono anche essere impostate a livello di codice nel modulo Property.Subproperty ( ad esempio , EmptyDataRowStyle.ForeColor). Le impostazioni comuni in genere includono un colore di sfondo personalizzato, il colore di primo piano e le proprietà del carattere.

Si applica a

Vedi anche