ImageField.AlternateText Propiedad

Definición

Obtiene o establece el texto alternativo que se muestra para una imagen en el objeto ImageField.

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

Valor de propiedad

String

Texto alternativo para una imagen presentada en el objeto ImageField. 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 AlternateText propiedad para especificar el texto alternativo para todas las imágenes que se muestran en un ImageField objeto .


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

Comentarios

Utilice la AlternateText propiedad para especificar el texto alternativo para las imágenes que se muestran en un ImageField objeto . El texto alternativo se muestra cuando una imagen no se puede cargar o no está disponible. Los exploradores que admiten la característica Información sobre herramientas también muestran este texto como información sobre herramientas.

Nota

Cuando se establece esta propiedad, todas las imágenes que se muestran en un ImageField objeto comparten el mismo texto alternativo. Como alternativa, puede enlazar el texto alternativo a un campo de un origen de datos estableciendo la DataAlternateTextField propiedad en lugar de esta propiedad. Esto le permite tener texto alternativo diferente para cada imagen mostrada. Si se establecen las AlternateText propiedades y DataAlternateTextField , la DataAlternateTextField propiedad tiene prioridad.

El valor de esta propiedad, cuando se establece, se puede guardar automáticamente en un archivo de recursos mediante una herramienta de diseñador. Para obtener más información, consulte LocalizableAttribute Globalización y localización.

Se aplica a

Consulte también