Export (0) Print
Expand All

HyperLinkField.DataTextField Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the name of the field from the data source containing the text to display for the hyperlink captions in the HyperLinkField object.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual string DataTextField { get; set; }
/** @property */
public String get_DataTextField ()

/** @property */
public void set_DataTextField (String value)

public function get DataTextField () : String

public function set DataTextField (value : String)

Property Value

The name of the field from the data source containing the values to display for the hyperlink captions in the HyperLinkField. The default is an empty string (""), which indicates that this property is not set.

Use the DataTextField property to specify the name of the field that contains the text to display for the hyperlink captions in the HyperLinkField object.

Instead of using this property to bind the hyperlink captions to a field, you can use the Text property to set the hyperlink captions to a static value. With this option, each hyperlink shares the same caption.

NoteNote

If the DataTextField and Text properties are both set, the DataTextField property takes precedence.

The following code example demonstrates how to use the DataTextField property to specify a field from the data source to bind to the hyperlink captions displayed in a HyperLinkField object.


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

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


The following code example demonstrates how to use the DataTextFormatString property to format the values bound to the hyperlink captions displayed in a HyperLinkField object. The values are formatted as currency.


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


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft