ImageField.DataAlternateTextField 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定資料來源中的欄位名稱,這個欄位的值將繫結至 AlternateText 物件中每個影像的 ImageField 屬性。
public:
virtual property System::String ^ DataAlternateTextField { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string DataAlternateTextField { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string DataAlternateTextField { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.DataAlternateTextField : string with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.DataAlternateTextField : string with get, set
Public Overridable Property DataAlternateTextField As String
屬性值
欄位名稱,這個欄位將繫結 AlternateText 物件中每個影像的 ImageField 屬性。
- 屬性
範例
下列範例程式碼示範如何使用 DataAlternateTextField 屬性,從資料來源指定功能變數名稱,其中包含要系結至 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"
dataalternatetextfield="LastName"
dataalternatetextformatstring="Photo: {0}"
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"
dataalternatetextfield="LastName"
dataalternatetextformatstring="Photo: {0}"
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>
備註
DataAlternateTextField使用 屬性可指定資料來源中包含要系結至 AlternateText 物件中 ImageField 每個影像之屬性之值的欄位名稱。 可讓您針對每個顯示的影像有不同的替代文字。 當無法載入或無法使用影像時,會顯示替代文字。 支援工具提示功能的瀏覽器也會將此文字顯示為工具提示。
注意
您可以藉由設定 AlternateText 屬性而非此屬性,指定套用至所有影像的替代文字。 如果 同時 AlternateText 設定 和 DataAlternateTextField 屬性,則 DataAlternateTextField 欄位會優先使用。