ImageField.NullDisplayText Proprietà

Definizione

Ottiene o imposta il testo da visualizzare in un oggetto ImageField quando il valore del campo specificato dalla proprietà DataImageUrlField è null.

public:
 virtual property System::String ^ NullDisplayText { System::String ^ get(); void set(System::String ^ value); };
public virtual string NullDisplayText { get; set; }
member this.NullDisplayText : string with get, set
Public Overridable Property NullDisplayText As String

Valore della proprietà

String

Testo visualizzato quando il valore di un campo è null. Il valore predefinito è una stringa vuota (""), a indicare che questa proprietà non è impostata.

Esempio

Nell'esempio seguente viene illustrato come usare la NullDisplayText proprietà per specificare il testo da visualizzare quando il valore del campo specificato dalla DataImageUrlField proprietà è null.


<%@ 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>ImageField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ImageField Example</h3>
                       
      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"  
        runat="server">
      
        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            alternatetext="Employee Photo"
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>
        
        </columns>
        
      </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.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        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>ImageField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>ImageField Example</h3>
                       
      <asp:gridview id="EmployeesGrid"
        autogeneratecolumns="false"
        datasourceid="EmployeeSource"  
        runat="server">
      
        <columns>

          <asp:imagefield dataimageurlfield="PhotoPath"
            alternatetext="Employee Photo"
            nulldisplaytext="No image on file."
            headertext="Photo"  
            readonly="true"/>
          <asp:boundfield datafield="FirstName"
            headertext="First Name"/>
          <asp:boundfield datafield="LastName"
            headertext="Last Name"/>
        
        </columns>
        
      </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.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

Commenti

Quando il valore del campo specificato dalla DataImageUrlField proprietà è null, non è possibile visualizzare un'immagine in un ImageField oggetto. Utilizzare la NullDisplayText proprietà per specificare il testo da visualizzare nel posto dell'immagine. Il testo indica in genere che l'immagine normale non è disponibile o non può essere trovata.

Nota

In alternativa, è possibile visualizzare un'immagine alternativa quando il valore del campo è null impostando la proprietà anziché questa NullImageUrl proprietà. Se le NullImageUrl proprietà e NullDisplayText sono entrambe impostate, la NullImageUrl proprietà ha la precedenza.

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

Si applica a

Vedi anche