HyperLinkField.DataTextField プロパティ

定義

HyperLinkField オブジェクトに表示されるハイパーリンクのキャプションとして使用するテキストが格納されている、データ ソース内のフィールド名を取得または設定します。

public:
 virtual property System::String ^ DataTextField { 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 DataTextField { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string DataTextField { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.DataTextField : 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.DataTextField : string with get, set
Public Overridable Property DataTextField As String

プロパティ値

String

HyperLinkField のハイパーリンクのキャプションとして表示する値が格納されている、データ ソース内のフィールド名。 既定値は空の文字列 ("") です。このプロパティが設定されていないことを示します。

属性

次のコード例では、プロパティを DataTextField 使用して、オブジェクトに表示されるハイパーリンク キャプションにバインドするデータ ソースのフィールドを指定する方法を HyperLinkField 示します。


<%@ 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 DataBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField DataBinding Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- Bind the CompanyName and HomePage fields from the   -->
      <!-- Northwind database to the caption and URL of the    -->
      <!-- hyperlinks in the HyperLinkField field column. Note -->
      <!-- that the URLs specified in the Northwind database   -->
      <!-- might not be valid URLs.                            -->
      <asp:gridview id="SuppliersGridView" 
        datasourceid="SuppliersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:hyperlinkfield datatextfield="CompanyName"
            datanavigateurlfields="HomePage"          
            headertext="Company Name"
            target="_blank" />
          <asp:boundfield datafield="City" 
            headertext="City"/>
                 
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="SuppliersSqlDataSource"  
        selectcommand="SELECT [SupplierID], [CompanyName], [City], [HomePage] FROM [Suppliers]"
        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 DataBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>HyperLinkField DataBinding Example</h3>
                    
      <!-- Populate the Columns collection declaratively. -->
      <!-- Bind the CompanyName and HomePage fields from the   -->
      <!-- Northwind database to the caption and URL of the    -->
      <!-- hyperlinks in the HyperLinkField field column. Note -->
      <!-- that the URLs specified in the Northwind database   -->
      <!-- might not be valid URLs.                            -->
      <asp:gridview id="SuppliersGridView" 
        datasourceid="SuppliersSqlDataSource" 
        autogeneratecolumns="false"
        runat="server">
                
        <columns>
                
          <asp:hyperlinkfield datatextfield="CompanyName"
            datanavigateurlfields="HomePage"          
            headertext="Company Name"
            target="_blank" />
          <asp:boundfield datafield="City" 
            headertext="City"/>
                 
        </columns>
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Northwind sample database.                   -->
      <asp:sqldatasource id="SuppliersSqlDataSource"  
        selectcommand="SELECT [SupplierID], [CompanyName], [City], [HomePage] FROM [Suppliers]"
        connectionstring="server=localhost;database=northwind;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

次のコード例では、プロパティを DataTextFormatString 使用して、オブジェクトに表示されるハイパーリンク キャプションにバインドされた値の書式を設定する方法を HyperLinkField 示します。 値は通貨として書式設定されます。


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

注釈

プロパティを DataTextField 使用して、オブジェクト内のハイパーリンクキャプションに表示するテキストを含むフィールドの名前を HyperLinkField 指定します。

このプロパティを使用してハイパーリンクキャプションをフィールドにバインドする代わりに、このプロパティを Text 使用してハイパーリンクのキャプションを静的な値に設定できます。 このオプションを使用すると、各ハイパーリンクは同じキャプションを共有します。

注意

プロパティとTextプロパティのDataTextField両方が設定されている場合は、プロパティがDataTextField優先されます。

適用対象

こちらもご覧ください