[thelist] .NET [C#], DropDownList, HTMLEncode

jason.handby jason.handby at corestar.co.uk
Thu Sep 7 09:55:36 CDT 2006

Hi Chris,

Thanks for all the clarifications you've posted today...

Your database string is stored as an HTML-encoded string, using HTML
entities (beginning '&') to represent Greek characters.

The strings you provide to your DropDownList are being HTMLEncoded when
they are rendered as HTML by ASP.NET.

Because your string is already encoded, this means that it ends up being
double-encoded and thus comes out looking weird on the page -- the
ampersand (a reserved character in HTML) is replaced with '&' during
the second encoding.

So I think you need to use Server.HtmlDecode() to un-encode your
database string before you give it to the DropDownList, so that it will
only be HTMLEncoded once, when ASP.NET renders it.


Your input string from the database is "ñ"

Once you pass that through Server.HtmlDecode() it becomes some sequence
of Greek characters.

You pass that decoded string to the constructor for your list item.

When the list item is rendered to HTML, ASP.NET will HTMLEncode it
again, leaving it as the (already-encoded) string you got from your
database to start with.

This string will be rendered by the browser as a sequence of Greek

This really ought to work!


More information about the thelist mailing list