I ran into this one today, alternative solutions are welcome…
If you’re programatically adding items to an ASP.NET dropdown list, you do it with something like this:
_cboDropDown.Items.Add(new ListItem(”Item Text”, “Item Value”));
Which is fine for most cases, but unlike with, say, the Text property of the Label control, ASP.NET will HTML encode the text before rendering it, so if you have something like:
_cboDropDown.Items.Add(new ListItem(”Brand X®”, “1131″));
It’ll show up in the dropdown as “Brand X®” instead of the intended “Brand X®”
What’s a poor developer to do?
I ended up using the Server.HtmlDecode() method, as follows:
_cboDropDown.Items.Add(new ListItem(Server.HtmlDecode(”Brand X®”), “1131″));
…and it’s all good, if a little ugly for my tastes. Has anyone got a better idea?
Valera | 14-Dec-07 at 3:38 pm | Permalink
Thanks Jason for the post - this is what I was looking for!