HyperLinkField クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
データ バインド コントロールのハイパーリンクとして表示されるフィールドを表します。
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 オブジェクトを使用して、 GridView コントロール内の静的ハイパーリンクの列を表示する方法を示します。 HyperLinkField オブジェクト内の各ハイパーリンクは、TextプロパティとNavigateUrlプロパティで指定されたのと同じキャプションとナビゲーション 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 オブジェクトをデータ ソース内のフィールドにバインドする方法を示しています。 DataTextFieldプロパティとDataNavigateUrlFieldsプロパティを使用して、キャプションにバインドするフィールドと、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 クラスは、データ バインド コントロール (GridViewやDetailsViewなど) によって、表示される各レコードのハイパーリンクを表示するために使用されます。 ユーザーがハイパーリンクをクリックすると、ハイパーリンクに関連付けられている Web ページに移動します。 HyperLinkField オブジェクトは、使用されているデータ バインド コントロールによって異なる方法で表示されます。 たとえば、 GridView コントロールは HyperLinkField オブジェクトを列として表示し、 DetailsView コントロールは行として表示します。
ハイパーリンクに表示するキャプションを指定するには、 Text プロパティを使用します。 NavigateUrl プロパティを使用して、ハイパーリンクがクリックされたときに移動する URL を指定します。 リンクされたコンテンツを特定のウィンドウまたはフレームに表示する場合は、 Target プロパティを設定します。
Note
TextプロパティとNavigateUrlプロパティが設定されている場合、HyperLinkField オブジェクト内のすべてのハイパーリンクは同じキャプションとナビゲーション URL を共有します。 同様に、 Target プロパティはすべてのハイパーリンクにも適用されます。
または、 HyperLinkField オブジェクトをデータ ソース内のフィールドにバインドすることもできます。 これにより、 HyperLinkField オブジェクト内のハイパーリンクごとに異なるキャプションを表示し、各ハイパーリンクを別の場所に移動することができます。 フィールドをキャプションにバインドするには、 DataTextField プロパティを設定します。 ナビゲーション用の URL を作成するには、 DataNavigateUrlFields プロパティを、URL の作成に使用するフィールドのコンマ区切りのリストに設定します。
DataTextFormatStringプロパティとDataNavigateUrlFormatStringプロパティをそれぞれ設定することで、キャプションとナビゲーション URL のカスタム形式を指定できます。
HyperLinkField プロパティを Visible に設定することで、データ バインド コントロール内のfalse オブジェクトを非表示にすることができます。
HyperLinkField オブジェクトのヘッダー セクションとフッター セクションをカスタマイズできます。 ヘッダーセクションまたはフッターセクションにキャプションを表示するには、それぞれ HeaderText プロパティまたは FooterText プロパティを設定します。 テキストの代わりにヘッダー セクションに画像を表示するには、 HeaderImageUrl プロパティを設定します。 ヘッダー セクションは、HyperLinkField プロパティを ShowHeader に設定することで、false オブジェクトで非表示にすることができます。
Note
一部のデータ バインド コントロール ( GridView コントロールなど) では、コントロールのヘッダー セクション全体のみを表示または非表示にすることができます。 これらのデータ バインド コントロールは、個々のバインドされたフィールドの ShowHeader プロパティをサポートしていません。 データ バインド コントロールのヘッダー セクション全体を表示または非表示にするには、コントロールの ShowHeader プロパティ (使用可能な場合) を使用します。
また、フィールドのさまざまな部分のスタイル プロパティを設定して、 HyperLinkField オブジェクトの外観 (フォントの色、背景色など) をカスタマイズすることもできます。 次の表に、さまざまなスタイル プロパティを示します。
| Style プロパティ | Description |
|---|---|
| ControlStyle | HyperLinkField オブジェクトの子 Web サーバー コントロールのスタイル設定。 |
| FooterStyle | HyperLinkField オブジェクトのフッター セクションのスタイル設定。 |
| HeaderStyle | HyperLinkField オブジェクトのヘッダー セクションのスタイル設定。 |
| ItemStyle | HyperLinkField オブジェクト内のデータ項目のスタイル設定。 |
コンストラクター
| 名前 | 説明 |
|---|---|
| HyperLinkField() |
HyperLinkField クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| AccessibleHeaderText |
一部のコントロールの |
| 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 オブジェクト内のハイパーリンクがクリックされたときにリンクされた Web ページを表示する対象のウィンドウまたはフレームを取得または設定します。 |
| Text |
HyperLinkField オブジェクト内のハイパーリンクごとに表示するテキストを取得または設定します。 |
| ValidateRequestMode |
コントロールがクライアント入力を検証するかどうかを指定する値を取得または設定します。 (継承元 DataControlField) |
| ViewState |
同じページに対する複数の要求にわたって、 DataControlField オブジェクトのビュー ステートを保存および復元できる状態情報のディクショナリを取得します。 (継承元 DataControlField) |
| Visible |
データ コントロール フィールドがレンダリングされるかどうかを示す値を取得または設定します。 (継承元 DataControlField) |
メソッド
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| IDataSourceViewSchemaAccessor.DataSourceViewSchema |
この DataControlField オブジェクトに関連付けられているスキーマを取得または設定します。 (継承元 DataControlField) |
| IStateManager.IsTrackingViewState |
DataControlField オブジェクトがビュー ステートへの変更を保存しているかどうかを示す値を取得します。 (継承元 DataControlField) |
| IStateManager.LoadViewState(Object) |
データ コントロール フィールドの以前に保存したビューステートを復元します。 (継承元 DataControlField) |
| IStateManager.SaveViewState() |
ページがサーバーにポストバックされてから、 DataControlField ビューステートに加えられた変更を保存します。 (継承元 DataControlField) |
| IStateManager.TrackViewState() |
DataControlField オブジェクトがビューステートの変更を追跡し、コントロールのViewState プロパティに格納し、同じページに対する要求間で永続化できるようにします。 (継承元 DataControlField) |