Why does GridView not decode HTML?

Posted on 2008-11-13
Last Modified: 2013-11-08
In 3.5, I'm adding values to a Dictionary<string, string>, which I then assign to a GridView.  I do a

string mystring = "<a href="">go here</a>";
myDictionary.Add("KeyOne", Server.HtmlDecode(mystring));

but in the aspx, it comes out in the grid as the full string rather than a clickable link.  When I view source, I can see it has turned the carrots into escaped characters.  What am I doing wrong?  I've also tried UrlDecode().
Question by:brettr
    1 Comment
    LVL 7

    Accepted Solution

    It depends on the fields of the GridView. By default (with AutoGenerateColumns=true) you get a bound field that is set to encode HTML.

    You can use the following:
    <asp:gridview ...>
         <asp:boundfield datafield="Country" htmlencode="false" headertext="Country"/>



    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 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

    22 Experts available now in Live!

    Get 1:1 Help Now