Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

HyperLinkColumn.FormatDataNavigateUrlValue Method

Formats a data-bound URL using the format specified by the DataNavigateUrlFormatString property.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
protected virtual string FormatDataNavigateUrlValue(
	Object dataUrlValue
)

Parameters

dataUrlValue
Type: System.Object
The data-bound URL to format.

Return Value

Type: System.String
The data-bound URL in the format specified by the DataNavigateUrlFormatString property.

Use the FormatDataNavigateUrlValue method to format a data-bound URL value with the format specified by the DataNavigateUrlFormatString property.

NoteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.


<!-- 
This example demonstrates using a hyperlink column. The code below
should be copied into a file called HyperTextColumnCS.aspx.  The file
should be stored in the same directory as the file DetailsPageCS.aspx
described below.
-->


...


<%@ Page language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    private DataView dv;
    private DataTable dt = new DataTable();

    private void Page_Load(object sender, System.EventArgs e)
    {
        // Create a DataTable to use as the data source for 
        // the DataGrid.
        dt.Columns.Add(new DataColumn("ItemNumber"));
        dt.Columns["ItemNumber"].Caption = "Item Number";
        dt.Columns.Add(new DataColumn("Item"));
        dt.Columns["ItemNumber"].Caption = "Item";
        dt.Columns.Add(new DataColumn("Price"));
        dt.Columns["ItemNumber"].Caption = "Price";

        // Add some data to the DataTable.
        DataRow myDataRow;
        for (int i = 0; i < 5; i++)
        {
            myDataRow = dt.NewRow();
            myDataRow[0] = i;
            myDataRow[1] = "Item " + i.ToString();
            myDataRow[2] = 1.23 * (i + 1);
            dt.Rows.Add(myDataRow);
        }

        // Use the table to create a DataView.
        dv = new DataView(dt);

        // Create hyperlink columns that contain the item name
        // and price.
        HyperLinkColumn nameCol = new HyperLinkColumn();
        nameCol.DataNavigateUrlField = "ItemNumber";
        nameCol.DataTextField = "Item";
        nameCol.DataNavigateUrlFormatString = 
            "DetailspageCS.aspx?id={0}";
        nameCol.HeaderText = dt.Columns["Item"].Caption;

        HyperLinkColumn priceCol = new HyperLinkColumn();
        priceCol.DataNavigateUrlField = "ItemNumber";
        priceCol.DataTextField = "Price";
        priceCol.DataNavigateUrlFormatString = 
            "DetailspageCS.aspx?id={0}";
        priceCol.DataTextFormatString = "{0:c}";
        priceCol.HeaderText = dt.Columns["Price"].Caption;

        // Add the new columns to the DataGrid.
        DataGrid1.Columns.Add(nameCol);
        DataGrid1.Columns.Add(priceCol);

        // Set the DataView as the data source, and bind 
        // it to the DataGrid.
        DataGrid1.DataSource = dv;
        DataGrid1.DataBind();

    }

    private void DataGrid1_ItemDataBound(object sender, 
        System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        ListItemType itemType = (ListItemType)e.Item.ItemType;

        if ((itemType != ListItemType.Header) &&
            (itemType != ListItemType.Footer) &&
            (itemType != ListItemType.Separator))
        {

            // Get the IntegerValue cell from the grid's column 
            // collection.
            TableCell currentCell = (TableCell)e.Item.Controls[0];
            DataGrid1.Columns[1].InitializeCell(currentCell, 1,
                ListItemType.Item);

            // Add attributes to the cell.
            currentCell.Attributes.Add("id", "currentCell" + 
                e.Item.ItemIndex.ToString());
            currentCell.Attributes.Add("OnClick",
                "Update_currentCell" +
                e.Item.ItemIndex.ToString() +
                "()");
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>HyperLinkColumn Example</title>
</head>
    <body>
        <form id="form1" runat="server">
            <h3>HyperLinkColumn Example</h3>
                <asp:DataGrid Runat="server" ID="DataGrid1" CellPadding="4"
                    AutoGenerateColumns="False" BorderStyle="None" GridLines="None">
                    <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="Black">
                    </HeaderStyle>
                </asp:DataGrid>
                <p>Click on an item name or price to add the item to your order.</p>
        </form>
    </body>
</html>



<!-- 
This example demonstrates using a hyperlink column. The code below
should be copied into a file called DetailsPageCS.aspx. The file
should be stored in the same directory as the file HyperTextColumn.CS
described above.
-->


...


<%@ Page language="c#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Data" %>

<!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>
    <title>HyperLinkColumn Example</title>
<script runat="server">
            private DataView dv;
            private DataTable dt = new DataTable();

            private void Page_Load(object sender, System.EventArgs e)
            {
                // Get the item value that was passed on the query string.
                NameValueCollection myCollection = Request.QueryString; 
                string selectedItem = myCollection.Get("id");

                Label1.Text = "Item " + selectedItem + 
                    " has been added to your order.";
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <h3>HyperLinkColumn Example</h3>
                <p><asp:Label id="Label1" runat="server">Label</asp:Label></p>
                <p><asp:HyperLink id="HyperLink1" runat="server" 
                    BorderColor="#8080FF" BorderStyle="Groove" ForeColor="Blue"
                    NavigateUrl="HyperTextColumnCS.aspx"> return to items page 
                   </asp:HyperLink></p>
        </form>
    </body>
</html>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.