GridView.EmptyDataText Proprietà

Definizione

Ottiene o imposta il testo da visualizzare nella riga di dati vuota di cui viene eseguito il rendering quando un controllo GridView è associato a un'origine dati che non contiene record.

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

Valore della proprietà

Il testo da visualizzare nella riga di dati vuota. Il valore predefinito è una stringa vuota (""), a indicare che questa proprietà non è impostata.

Esempio

Nell'esempio seguente viene illustrato come utilizzare la EmptyDataText proprietà per specificare il testo da visualizzare nella riga di dati vuota.


<%@ 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>GridView EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView EmptyDataText Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        emptydatatext="No data in the data source."
        runat="server">
        
        <emptydatarowstyle backcolor="LightBlue"
          forecolor="Red"/>
                
      </asp:gridview>
            
      <!-- 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 following query        -->
      <!-- returns an empty data source to demonstrate the      -->
      <!-- empty row.                                           -->
      <asp:sqldatasource id="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'"
        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>GridView EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView EmptyDataText Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        emptydatatext="No data in the data source."
        runat="server">
        
        <emptydatarowstyle backcolor="LightBlue"
          forecolor="Red"/>
                
      </asp:gridview>
            
      <!-- 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 following query        -->
      <!-- returns an empty data source to demonstrate the      -->
      <!-- empty row.                                           -->
      <asp:sqldatasource id="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

Commenti

La riga di dati vuota viene visualizzata in un GridView controllo quando l'origine dati associata al controllo non contiene record. Utilizzare la EmptyDataText proprietà per specificare il testo da visualizzare nella riga di dati vuota. Per controllare lo stile della riga di dati vuota, utilizzare la EmptyDataRowStyle proprietà . In alternativa, è possibile definire un'interfaccia utente personalizzata per la riga di dati vuota impostando la EmptyDataTemplate proprietà anziché questa proprietà.

Nota

Se vengono impostate entrambe le EmptyDataText proprietà e EmptyDataTemplate , la proprietà ha la EmptyDataTemplate precedenza.

Il valore di questa proprietà, se impostato, può essere salvato automaticamente in un file di risorse usando uno strumento di progettazione. Per altre informazioni, vedere LocalizableAttribute Globalizzazione e localizzazione.

Si applica a

Vedi anche