ImageField.NullImageUrl Propiedad

Definición

Obtiene o establece la dirección URL de una imagen alternativa presentada en un objeto ImageField cuando el valor del campo especificado por la propiedad DataImageUrlField es null.

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

Valor de propiedad

Dirección URL a una imagen alternativa que se muestra cuando el valor de un campo es null. El valor predeterminado es una cadena vacía (""), lo que indica que no se ha establecido esta propiedad.

Ejemplos

En el ejemplo siguiente se muestra cómo usar la NullImageUrl propiedad para especificar la dirección URL en una imagen alternativa que se va a mostrar cuando el valor del campo especificado por la DataImageUrlField propiedad es 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"
            nullimageurl="~\Images\NoPhoto.jpg"
            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"
            nullimageurl="~\Images\NoPhoto.jpg"
            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>

Comentarios

Cuando el valor del campo especificado por la DataImageUrlField propiedad es null, no se puede mostrar una imagen en un ImageField objeto . Utilice la NullImageUrl propiedad para especificar la dirección URL en una imagen alternativa que se va a mostrar. La imagen alternativa suele ser una imagen que indica que la imagen normal no está disponible o no se encuentra.

Nota

Como alternativa, puede simplemente mostrar texto cuando el valor del campo es null estableciendo la NullDisplayText propiedad en lugar de esta propiedad. Si se establecen las NullImageUrl propiedades y NullDisplayText , la NullImageUrl propiedad tiene prioridad.

Se aplica a

Consulte también