How do I encode DataNavigateUrlFormatString to send URL that include "&"

Posted on 2008-11-12
Last Modified: 2012-08-13
I have a master/detail page and am trying to set up the hyperlink on the master page so I can open the detail page with a recordid that looks like:
This string may also include other characters that might not be valid html characters.
I see there is a Server.HTMLEncode(string) function, but, not sure how to use it/where to put it.

Currently, without encoding, the url that gets sent to open the new page looks like:
which doesn't work, but, if I insert the following hand encoded url in the browser, it works

Can the function get included in the DataNavigateUrlFormatString some how, or does it need to go elsewhere?
Here's some of my code from the master page that contains the hyperlink:
    <asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1"
            AutoGenerateColumns="False" Caption="Distributor List"  CaptionAlign="Top"
            AllowSorting="True" CellPadding="5" CellSpacing="5">
            <asp:HyperLinkField DataNavigateUrlFields="AccountNo"
                 Text="Profile" />
            <asp:BoundField DataField="ACCOUNTNO" HeaderText="ACCOUNTNO"
                SortExpression="ACCOUNTNO" />
            <asp:BoundField DataField="COMPANY" HeaderText="COMPANY"
                SortExpression="COMPANY" />
                SortExpression="TempID" />
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
            OldValuesParameterFormatString="original_{0}" SelectMethod="GetDistProfile"
Question by:avoorheis
    LVL 8

    Expert Comment

    Hi There,

    Here is some good information on the subject.


    Author Comment

    Thanks Sean,
    I've seen this page, but, since I'm a noob, I'm not sure where/how to use this function.
    Would it go into the DataNavigateUrlFormatString or elsewhere?
    like this
    I did try that and it didn't work, just not sure if this is the right place to use it or if it is, maybe my quotes are wrong.
    LVL 8

    Accepted Solution

    try this,

    Your using html encode scrap that and try the code below. Let me know how it  goes.


                    <asp:HyperLink ID="hypDetails" runat="server" NavigateUrl='<%# "Default3a.aspx?AccountNo=" + HttpUtility.UrlEncode(Eval("AccountNo").ToString())  %>' Text="Details" />

    Author Comment

    What a mouthful, I'll try and let you know....

    Author Comment

    That did it, thank you so much.
    Any recomendations to help me learn more about asp, books, websites, etc.

    thanks again!!!
    LVL 8

    Expert Comment

    I'm glad to help.
    I recommend this: You will not need to buy another book.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now