Last post Feb 05, 2009 03:49 AM by Nai-Dong Jin - MSFT
Feb 01, 2009 10:08 PM|greasepig|LINK
In my code I am binding ascii text (Japanese Characters) to a dropdownlist control. It appears stepping through all of the events of the control (i.e. bind, prerender, unload) the ascii character representation is correct. When the final page is rendered
the dropdown displayed has html encoded text values. When testing against other type of server side controls this does not appear to happen. Is there a way to turn off this default behavior of encoding on the dropdownlists?
Feb 02, 2009 02:29 AM|vik20000in|LINK
set HTMLEncode property to false.
Feb 02, 2009 10:23 AM|greasepig|LINK
Thank you for the reply. I am using ASP.NET 2.0, I do not see a HTMLEncode property for DropDownList controls in that version. Is there something I am not seeing?
Feb 05, 2009 03:20 AM|Momo_Stev|LINK
HtmlEncode is a method from Server.HTMLEncode. You need to use HTMLDecode method to decode all the contents which you'd like to bind to your ddl.
Feb 05, 2009 03:49 AM|Nai-Dong Jin - MSFT|LINK
In your scenario, you may use HtmlDecode method to check if the encoded characters can be decoded. Here's a sample.
String LoadDecodedFile(String file)
String DecodedString = "";
FileStream fs = new FileStream(file, FileMode.Open);
StreamReader r = new StreamReader(fs);
// Position the file pointer at the beginning of the file.
// Read the entire file into a string and decode each chunk.
while (r.Peek() > -1)
DecodedString += Server.HtmlDecode(r.ReadLine());
The sample retrieve the string from a file, and in your case, you can modify it according your scenario. And make sure that all the contents bound to the dropdownlist should be decoded.