Edit

Share via


HyperLinkField.DataNavigateUrlFormatString Property

Definition

Gets or sets the string that specifies the format in which the URLs for the hyperlinks in a HyperLinkField object are rendered.

public:
 virtual property System::String ^ DataNavigateUrlFormatString { System::String ^ get(); void set(System::String ^ value); };
public virtual string DataNavigateUrlFormatString { get; set; }
member this.DataNavigateUrlFormatString : string with get, set
Public Overridable Property DataNavigateUrlFormatString As String

Property Value

A string that specifies the format in which the URLs for the hyperlinks in a HyperLinkField are rendered. The default is an empty string (""), which indicates that no special formatting is applied to the URL values.

Examples

The following code example demonstrates how to use the DataNavigateUrlFormatString property to specify a custom format to apply to the navigation URLs of the hyperlinks displayed in a HyperLinkField object. The value of the field specified by the DataTextField property is passed as a query string to a Web page specified in the format string.


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

Remarks

Use the DataNavigateUrlFormatString property to specify a custom format for the URLs of the hyperlinks in a HyperLinkField object. If the DataNavigateUrlFormatString property is not set, the hyperlinks' URLs do not get any special formatting.

Note

The format string is applied only when the DataNavigateUrlFields property is set.

The format string can be any literal string and usually includes a placeholder for the field's value. For example, in the format string "Item Value: {0}", the {0} placeholder is replaced with the field's value in the HyperLinkField object. The rest of the format string is displayed as literal text.

Note

If the format string does not include a placeholder, the field's value from the data source is not included in the final display text.

The placeholder consists of two parts, separated by a colon and wrapped in braces, in the form {A:Bxx}. The value before the colon (A in the general example) specifies the field value's index in a zero-based list of parameters.

Note

This parameter is part of the formatting syntax. Because there is only one field value in each cell, this value can only be set to 0.

The colon and the values after the colon are optional. The character after the colon (B in the general example) specifies the format in which to display the value. The following table lists the common formats.

Format character Description
C Displays numeric values in currency format.
D Displays numeric values in decimal format.
E Displays numeric values in scientific (exponential) format.
F Displays numeric values in fixed format.
G Displays numeric values in general format.
N Displays numeric values in number format.
X Displays numeric values in hexadecimal format.

Note

The format characters are not case-sensitive, except for X, which displays the hexadecimal characters in the case specified.

The value after the format character (xx in the general example) specifies the number of significant digits or decimal places to display. For example, the format string "{0:F2}" displays a fixed-point number with two decimal places.

For more information on formatting strings, see Formatting Types.

Applies to

See also