ImageField.AlternateText Właściwość

Definicja

Pobiera lub ustawia alternatywny tekst wyświetlany dla obrazu w ImageField obiekcie.

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

Wartość właściwości

String

Alternatywny tekst obrazu wyświetlanego ImageField w obiekcie. Wartość domyślna to pusty ciąg (""), który wskazuje, że ta właściwość nie jest ustawiona.

Przykłady

W poniższym przykładzie pokazano, jak za pomocą AlternateText właściwości określić alternatywny tekst dla wszystkich obrazów wyświetlanych w ImageField obiekcie.


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

Uwagi

AlternateText Użyj właściwości , aby określić alternatywny tekst obrazów wyświetlanych w ImageField obiekcie. Tekst alternatywny jest wyświetlany, gdy nie można załadować obrazu lub jest niedostępny. Przeglądarki, które obsługują funkcję Etykietki narzędzi, również wyświetlają ten tekst jako etykietkę narzędzia.

Uwaga

Po ustawieniu tej właściwości wszystkie obrazy wyświetlane w ImageField obiekcie współdzielą ten sam tekst alternatywny. Alternatywnie możesz powiązać tekst alternatywny z polem w źródle danych, ustawiając DataAlternateTextField właściwość zamiast tej właściwości. Dzięki temu można mieć inny tekst alternatywny dla każdego wyświetlanego obrazu. Jeśli właściwości AlternateText i DataAlternateTextField są ustawione, DataAlternateTextField właściwość ma pierwszeństwo.

Wartość tej właściwości, po ustawieniu, można zapisać automatycznie w pliku zasobów przy użyciu narzędzia projektanta. Aby uzyskać więcej informacji, zobacz LocalizableAttribute temat Globalizacja i Lokalizacja.

Dotyczy

Zobacz też