HyperLinkField 類別

定義

代表在資料繫結控制項中顯示為超連結的欄位。

public ref class HyperLinkField : System::Web::UI::WebControls::DataControlField
public class HyperLinkField : System.Web.UI.WebControls.DataControlField
type HyperLinkField = class
    inherit DataControlField
Public Class HyperLinkField
Inherits DataControlField
繼承
HyperLinkField

範例

下列程式碼範例示範如何使用 HyperLinkField 物件,在 控制項中 GridView 顯示靜態超連結的資料行。 物件中的每個 HyperLinkField 超連結都會分別共用 和 NavigateUrl 屬性所 Text 指定的相同標題和流覽 URL。


<%@ 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>HyperLinkField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- Set the HyperLinkField field column to a static     -->
      <!-- caption and URL.                                    -->
      <asp:gridview id="OrdersGridView" 
        datasourceid="OrdersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="OrderID" 
            headertext="OrderID"/>
          <asp:boundfield datafield="CustomerID" 
            headertext="Customer ID"/>
          <asp:boundfield datafield="OrderDate" 
            headertext="Order Date"
            dataformatstring="{0:d}" />
          <asp:hyperlinkfield text="Details..."
            navigateurl="~\details.aspx"            
            headertext="Order Details"
            target="_blank" />
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrdersSqlDataSource"  
        selectcommand="SELECT [OrderID], [CustomerID], [OrderDate] FROM [Orders]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </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>HyperLinkField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- Set the HyperLinkField field column to a static     -->
      <!-- caption and URL.                                    -->
      <asp:gridview id="OrdersGridView" 
        datasourceid="OrdersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="OrderID" 
            headertext="OrderID"/>
          <asp:boundfield datafield="CustomerID" 
            headertext="Customer ID"/>
          <asp:boundfield datafield="OrderDate" 
            headertext="Order Date"
            dataformatstring="{0:d}" />
          <asp:hyperlinkfield text="Details..."
            navigateurl="~\details.aspx"            
            headertext="Order Details"
            target="_blank" />
                
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrdersSqlDataSource"  
        selectcommand="SELECT [OrderID], [CustomerID], [OrderDate] FROM [Orders]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

下列程式碼範例示範如何將 物件系結 HyperLinkField 至資料來源中的欄位。 DataTextFieldDataNavigateUrlFields 屬性可用來指定欄位,分別系結至 物件中顯示的 HyperLinkField 每個超連結標題和導覽 URL。


<%@ 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>HyperLinkField Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- The UnitPrice field values are bound to the         -->
      <!-- captions of the hyperlinks in the HyperLinkField    -->
      <!-- field column, formatted as currency. The ProductID  -->
      <!-- field values are bound to the navigate URLs of the  -->
      <!-- hyperlinks. However, instead of being the actual    -->
      <!-- URL values, the product ID is passed to the linked  -->
      <!-- page as a parameter in the URL specified by the     -->
      <!-- DataNavigateUrlFormatString property.               -->
      <asp:gridview id="OrdersGridView" 
        datasourceid="OrdersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="OrderID" 
            headertext="Order ID"/>
          <asp:boundfield datafield="ProductID" 
            headertext="Product ID"/>
          <asp:hyperlinkfield datatextfield="UnitPrice"
            datatextformatstring="{0:c}"
            datanavigateurlfields="ProductID"
            datanavigateurlformatstring="~\details.aspx?ProductID={0}"          
            headertext="Price"
            target="_blank" />
          <asp:boundfield datafield="Quantity" 
            headertext="Quantity"/>
                 
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrdersSqlDataSource"  
        selectcommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity] FROM [Order Details]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </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>HyperLinkField DataTextFormatString and DataNavigateUrlFormatString Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField DataTextFormatString and DataNavigateUrlFormatString Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- The UnitPrice field values are bound to the         -->
      <!-- captions of the hyperlinks in the HyperLinkField    -->
      <!-- field column, formatted as currency. The ProductID  -->
      <!-- field values are bound to the navigate URLs of the  -->
      <!-- hyperlinks. However, instead of being the actual    -->
      <!-- URL values, the product ID is passed to the linked  -->
      <!-- page as a parameter in the URL specified by the     -->
      <!-- DataNavigateUrlFormatString property.               -->
      <asp:gridview id="OrdersGridView" 
        datasourceid="OrdersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:boundfield datafield="OrderID" 
            headertext="Order ID"/>
          <asp:boundfield datafield="ProductID" 
            headertext="Product ID"/>
          <asp:hyperlinkfield datatextfield="UnitPrice"
            datatextformatstring="{0:c}"
            datanavigateurlfields="ProductID"
            datanavigateurlformatstring="~\details.aspx?ProductID={0}"          
            headertext="Price"
            target="_blank" />
          <asp:boundfield datafield="Quantity" 
            headertext="Quantity"/>
                 
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="OrdersSqlDataSource"  
        selectcommand="SELECT [OrderID], [ProductID], [UnitPrice], [Quantity] FROM [Order Details]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

備註

資料 HyperLinkField 繫結控制項會使用 類別 (,例如 GridViewDetailsView) ,以顯示所顯示每個記錄的超連結。 當使用者按一下超連結時,會導向至與超連結相關聯的網頁。 根據所使用的資料繫結控制項,物件 HyperLinkField 會以不同的方式顯示。 例如, GridView 控制項會將物件顯示為 HyperLinkField 資料行,而 DetailsView 控制項則會將其顯示為數據列。

若要指定要顯示超連結的標題,請使用 Text 屬性。 NavigateUrl使用 屬性可指定要在按一下超連結時流覽至的 URL。 如果您想要在特定視窗或框架中顯示連結的內容,請設定 Target 屬性。

注意

Text設定 和 NavigateUrl 屬性時,物件中的所有 HyperLinkField 超連結都會共用相同的標題和導覽 URL。 同樣地, Target 屬性也適用于所有超連結。

或者,您可以將 物件系結 HyperLinkField 至資料來源中的欄位。 這可讓您顯示 物件中 HyperLinkField 每個超連結的不同標題,並讓每個超連結流覽至不同的位置。 若要將欄位系結至標題,請設定 DataTextField 屬性。 若要建立導覽的 URL,請將 DataNavigateUrlFields 屬性設定為逗號分隔的欄位清單,以用來建立 URL。

您可以分別設定 DataTextFormatStringDataNavigateUrlFormatString 屬性,以指定標題和導覽 URL 的自訂格式。

您可以將 屬性設定 Visiblefalse ,以隱藏 HyperLinkField 資料繫結控制項中的 物件。

您可以自訂 物件的頁首和頁尾區段 HyperLinkField 。 若要在頁首或頁尾區段中顯示標題,請分別設定 HeaderTextFooterText 屬性。 若要在標頭區段中顯示影像,而不是文字,請設定 HeaderImageUrl 屬性。 您可以將 屬性設定 ShowHeaderfalse ,以隱藏 物件中的 HyperLinkField 標頭區段。

注意

某些資料繫結控制項 (,例如 GridView 控制項) 只能顯示或隱藏控制項的整個標頭區段。 這些資料繫結控制項不支援 ShowHeader 個別綁定欄位的 屬性。 若要顯示或隱藏資料繫結控制項的整個標頭區段,請使用控制項的 屬性,如果有) ,請使用控制項 ShowHeader 的屬性 (。

您也可以藉由設定欄位不同部分的 HyperLinkField 樣式屬性,自訂物件的外觀 (字型色彩、背景色彩等等) 。 下表列出不同的樣式屬性。

Style 屬性 描述
ControlStyle 物件的子 Web 服務器控制項樣式 HyperLinkField 設定。
FooterStyle 物件的頁尾區段樣式 HyperLinkField 設定。
HeaderStyle 物件的標頭區段樣式 HyperLinkField 設定。
ItemStyle 物件中資料項目的 HyperLinkField 樣式設定。

建構函式

HyperLinkField()

初始化 HyperLinkField 類別的新執行個體。

屬性

AccessibleHeaderText

取得或設定在部分控制項中呈現為 AbbreviatedText 屬性值的文字。

(繼承來源 DataControlField)
Control

取得與 DataControlField 物件關聯之資料控制項的參考。

(繼承來源 DataControlField)
ControlStyle

取得 DataControlField 物件內含之任何 Web 伺服器控制項的樣式。

(繼承來源 DataControlField)
DataNavigateUrlFields

取得或設定資料來源中的欄位名稱,這些欄位用來建構 HyperLinkField 物件中超連結的 URL。

DataNavigateUrlFormatString

取得或設定字串,指定 HyperLinkField 物件中超連結之 URL 的呈現格式。

DataTextField

取得或設定資料來源中的欄位名稱,這個欄位包含 HyperLinkField 物件中超連結標題所要顯示的文字。

DataTextFormatString

取得或設定字串,指定 HyperLinkField 物件中超連結標題的顯示格式。

DesignMode

取得值,指示目前是否在設計階段環境中檢視資料控制項欄位。

(繼承來源 DataControlField)
FooterStyle

取得或設定資料控制項欄位的頁尾樣式。

(繼承來源 DataControlField)
FooterText

取得或設定顯示在資料控制項欄位之頁尾項目中的文字。

(繼承來源 DataControlField)
HeaderImageUrl

取得或設定顯示在資料控制項欄位的標頭項目中之影像的 URL。

(繼承來源 DataControlField)
HeaderStyle

取得或設定資料控制項欄位的標頭樣式。

(繼承來源 DataControlField)
HeaderText

取得或設定顯示在資料控制項欄位之標頭項目中的文字。

(繼承來源 DataControlField)
InsertVisible

取得值,指示 DataControlField 物件在其父資料繫結控制項處於插入模式時是否可見。

(繼承來源 DataControlField)
IsTrackingViewState

取得值,指出 DataControlField 物件是否正在將變更儲存到它的檢視狀態。

(繼承來源 DataControlField)
ItemStyle

取得由資料控制項欄位顯示之任何文字基礎內容的樣式。

(繼承來源 DataControlField)
NavigateUrl

取得或設定在按一下 HyperLinkField 物件中的超連結時所要巡覽的 URL。

ShowHeader

取得或設定值,指示是否呈現資料控制項欄位的標頭項目。

(繼承來源 DataControlField)
SortExpression

取得或設定資料來源控制項用於排序資料的排序運算式。

(繼承來源 DataControlField)
Target

取得或設定目標視窗或框架,在按一下 HyperLinkField 物件中的超連結時,這個視窗或框架會顯示連結的網頁。

Text

取得或設定 HyperLinkField 物件中每個超連結所要顯示的文字。

ValidateRequestMode

取得或設定值,這個值會指定控制項是否驗證用戶端輸入。

(繼承來源 DataControlField)
ViewState

取得狀態資訊的字典,允許您在相同頁面的多個要求之間,儲存和還原 DataControlField 物件的檢視狀態。

(繼承來源 DataControlField)
Visible

取得或設定值,指示是否呈現資料控制項欄位。

(繼承來源 DataControlField)

方法

CloneField()

建立目前 DataControlField 衍生物件的複本。

(繼承來源 DataControlField)
CopyProperties(DataControlField)

將目前 HyperLinkField 物件的屬性複製到指定的物件。

CreateField()

傳回 HyperLinkField 類別的新執行個體。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
ExtractValuesFromCell(IOrderedDictionary, DataControlFieldCell, DataControlRowState, Boolean)

從目前資料表儲存格中擷取資料控制項欄位的值,並將值加入至指定的 IDictionary 集合。

(繼承來源 DataControlField)
FormatDataNavigateUrlValue(Object[])

使用 DataNavigateUrlFormatString 屬性所指定的格式字串,格式化巡覽 URL。

FormatDataTextValue(Object)

使用 DataTextFormatString 屬性所指定的格式字串,格式化標題文字。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Initialize(Boolean, Control)

初始化 HyperLinkField 物件。

InitializeCell(DataControlFieldCell, DataControlCellType, DataControlRowState, Int32)

初始化 HyperLinkField 物件中的儲存格。

LoadViewState(Object)

將資料來源檢視還原成之前所儲存的檢視狀態。

(繼承來源 DataControlField)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnFieldChanged()

引發 FieldChanged 事件。

(繼承來源 DataControlField)
SaveViewState()

儲存自頁面回傳至伺服器以來對 DataControlField 檢視狀態所做的變更。

(繼承來源 DataControlField)
ToString()

傳回字串,表示這個 DataControlField 物件。

(繼承來源 DataControlField)
TrackViewState()

會造成 DataControlField 物件追蹤其檢視狀態變更,以將這些變更儲存在控制項的 ViewState 屬性中,並持續存取相同頁面的其他要求。

(繼承來源 DataControlField)
ValidateSupportsCallback()

表示 HyperLinkField 物件所包含的控制項支援回呼。

明確介面實作

IDataSourceViewSchemaAccessor.DataSourceViewSchema

取得或設定與此 DataControlField 物件相關聯的結構描述。

(繼承來源 DataControlField)
IStateManager.IsTrackingViewState

取得值,指出 DataControlField 物件是否正在將變更儲存到它的檢視狀態。

(繼承來源 DataControlField)
IStateManager.LoadViewState(Object)

將資料控制項欄位還原成先前儲存的檢視狀態。

(繼承來源 DataControlField)
IStateManager.SaveViewState()

儲存自頁面回傳至伺服器以來對 DataControlField 檢視狀態所做的變更。

(繼承來源 DataControlField)
IStateManager.TrackViewState()

會造成 DataControlField 物件追蹤其檢視狀態變更,以將這些變更儲存在控制項的 ViewState 屬性中,並持續存取相同頁面的其他要求。

(繼承來源 DataControlField)

適用於

另請參閱