ImageField.AlternateText プロパティ

定義

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

プロパティ値

ImageField オブジェクトに表示されるイメージの代替テキスト。 既定値は空の文字列 ("") です。このプロパティが設定されていないことを示します。

次の例では、 プロパティを AlternateText 使用して、オブジェクトに表示されるすべての画像の代替テキストを指定する方法を ImageField 示します。


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

注釈

プロパティを AlternateText 使用して、オブジェクトに表示される画像の代替テキストを ImageField 指定します。 代替テキストは、イメージを読み込めない場合、または使用できない場合に表示されます。 ツールヒント機能をサポートするブラウザーでも、このテキストがツールヒントとして表示されます。

注意

このプロパティを設定すると、オブジェクトに表示されるすべての画像が ImageField 同じ代替テキストを共有します。 別の方法として、このプロパティの代わりに プロパティを設定することで、代替テキストを DataAlternateTextField データ ソース内のフィールドにバインドできます。 これにより、表示される画像ごとに異なる代替テキストを使用できます。 プロパティと DataAlternateTextField プロパティのAlternateText両方が設定されている場合は、 プロパティがDataAlternateTextField優先されます。

このプロパティの値を設定すると、デザイナー ツールを使用してリソース ファイルに自動的に保存できます。 詳細については、グローバリゼーションとローカライズに関するページを参照してくださいLocalizableAttribute

適用対象

こちらもご覧ください