HyperLinkField クラスとは? わかりやすく解説

HyperLinkField クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

データ バインド コントロールハイパーリンクとして表示されるフィールド表します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class HyperLinkField
    Inherits DataControlField
Dim instance As HyperLinkField
public class HyperLinkField : DataControlField
public ref class HyperLinkField : public
 DataControlField
public class HyperLinkField extends DataControlField
public class HyperLinkField extends
 DataControlField
解説解説

データ バインド コントロール (GridView、DetailsView など) はこの HyperLinkField クラス使用して表示されるレコードハイパーリンク表示しますハイパーリンククリックされると、そのハイパーリンク関連付けられた Web ページユーザーリダイレクトます。HyperLinkField オブジェクトは、そのオブジェクト使用しているデータ バインド コントロールにより異なった形式表示されます。たとえば、HyperLinkField オブジェクトは、GridView コントロールでは列として表示されDetailsView コントロールでは行として表示されます。

ハイパーリンク表示するキャプション指定するには、Text プロパティ使用します。NavigateUrl プロパティ使用してハイパーリンククリックされたときの移動先となる URL指定しますリンク先内容特定のウィンドウまたはフレーム表示させるには、Target プロパティ設定します

メモメモ

Text プロパティおよび NavigateUrl プロパティ設定した場合HyperLinkField オブジェクト内のすべてのハイパーリンクで同じキャプションナビゲーション URL共有されます。同様にTarget プロパティすべてのハイパーリンク適用されます。

HyperLinkField オブジェクトデータ ソースフィールドバインドすることでも同じ設定を行うことができます。これにより、HyperLinkField オブジェクトハイパーリンクごとに異なキャプション表示したり、個々ハイパーリンク移動先に別々の場所を割り当てたりできますフィールドキャプションバインドするには、DataTextField プロパティ設定しますナビゲーション用の URL作成するには、DataNavigateUrlFields プロパティ対しURL作成使用するフィールドコンマ区切り指定します

キャプションおよびナビゲーション URL に対してカスタム書式指定するには、それぞれ、DataTextFormatString プロパティと DataNavigateUrlFormatString プロパティ設定します

Visible プロパティfalse設定すると、データ バインド コントロールHyperLinkField オブジェクトを非表示できます

また、HyperLinkField オブジェクトヘッダー セクションおよびフッター セクションカスタマイズできますヘッダー セクションまたはフッター セクションキャプション表示するには、HeaderText または FooterText プロパティ設定しますヘッダー セクションテキストではなくイメージ表示するには、HeaderImageUrl プロパティ設定します。ShowHeader プロパティfalse設定すると、HyperLinkField オブジェクトヘッダー セクションを非表示できます

また、フィールド各部分にスタイル プロパティ設定すると、HyperLinkField オブジェクト外観 (フォントの色や背景色など) をカスタマイズできますさまざまなスタイル プロパティの一覧を次の表に示します

使用例使用例

HyperLinkField オブジェクト使用してGridView コントロール静的ハイパーリンクの列を表示する方法次のコード例示しますHyperLinkField オブジェクト内のハイパーリンクは、Text プロパティNavigateUrl プロパティ指定された同じキャプションおよびナビゲーション URL共有します

<%@ Page language="VB" %>

<html>
  <body>
    <form 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="C#" %>

<html>
  <body>
    <form 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="VB" %>

<html>
  <body>
    <form 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>

<%@ Page language="C#" %>

<html>
  <body>
    <form 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>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.WebControls.DataControlField
    System.Web.UI.WebControls.HyperLinkField
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HyperLinkField メンバ
System.Web.UI.WebControls 名前空間
GridView クラス
GridView.Columns プロパティ
GridView.ShowHeader プロパティ
DetailsView クラス
DetailsView.Fields プロパティ
BoundField クラス
ButtonField クラス
ButtonFieldBase クラス
CheckBoxField クラス
CommandField クラス
DataControlField クラス
TemplateField
DataNavigateUrlFields
DataNavigateUrlFormatString
DataTextField
DataTextFormatString
NavigateUrl
Target
Text
DataControlField.Visible プロパティ



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HyperLinkField クラス」の関連用語

HyperLinkField クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HyperLinkField クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS