This documentation is archived and is not being maintained.

HyperLinkField Constructor

Initializes a new instance of the HyperLinkField class.

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

public HyperLinkField()

Use this constructor to initialize a new instance of the HyperLinkField class. This constructor is commonly used when adding fields to a dynamically created data-bound control.

To dynamically add a HyperLinkField object to a data-bound control, create a new HyperLinkField object, set its properties, and then add it to the data-bound control's field collection. For example, if you are using the GridView control, add the HyperLinkField object to the Columns collection.


Although you can dynamically add fields to a data-bound control, it is strongly recommended that fields be statically declared and then shown or hidden, as appropriate. Statically declaring all your fields reduces the size of the view state for the parent data-bound control.

The following code example demonstrates how to use the constructor to dynamically add a HyperLinkField object to a GridView control.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<script runat="server">

  void Page_Load(Object sender, EventArgs e)

    // Dynamically create field columns to display the desired 
    // fields from the data source. This only needs to be done 
    // the first time the page is loaded because the GridView 
    // control persists its column fields.  
    if (!IsPostBack)

      // Create a HyperLinkField object to display the company's  
      // name. 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.
      HyperLinkField companyNameBoundField = new HyperLinkField ();
      string[] dataNavigateUrlFields = { "HomePage" };

      companyNameBoundField.DataTextField = "CompanyName";
      companyNameBoundField.DataNavigateUrlFields = dataNavigateUrlFields;
      companyNameBoundField.HeaderText = "Company Name";
      companyNameBoundField.Target = "_blank";

      // Create a BoundField object to display the company's city.
      BoundField cityBoundField = new BoundField ();

      cityBoundField.DataField = "city";
      cityBoundField.HeaderText = "City";

      // Add the field columns to the Columns collection of the 
      // GridView control.
      SuppliersGridView.Columns.Add (companyNameBoundField);
      SuppliersGridView.Columns.Add (cityBoundField);




<html xmlns="" >
  <head runat="server">
    <title>HyperLinkField Constructor Example</title>
    <form id="form1" runat="server">

      <h3>HyperLinkField Constructor Example</h3>

      <asp:gridview id="SuppliersGridView" 

      <!-- 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"


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0