Export (0) Print
Expand All

HyperLinkField.NavigateUrl Property

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Gets or sets the URL to navigate to when a hyperlink in a HyperLinkField object is clicked.

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

public virtual string NavigateUrl { get; set; }

Property Value

Type: System.String
The URL to navigate to when a hyperlink in a HyperLinkField is clicked. The default is an empty string (""), which indicates that this property is not set.

Use the NavigateUrl property to specify the URL to navigate to when a hyperlink in a HyperLinkField object is clicked. When this property is set, each hyperlink shares the same navigation URL.

Instead of using this property to set the URL for the hyperlinks, you can use the DataNavigateUrlFields property to bind the URLs of the hyperlinks to a field in a data source. This allows you to have a different URL for each hyperlink.

NoteNote

If the DataNavigateUrlFields and NavigateUrl properties are both set, the DataNavigateUrlFields property takes precedence.

The following code example demonstrates how to use the NavigateUrl property to specify a static Web page to navigate to when a hyperlink in a HyperLinkField object is clicked.



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



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft