0

So I am adding items to a DropDownList from code behind, and I need those items to have an html content.

I add the items as follows:

ListItem _item = new ListItem("<span style='color:red;'> some item</span>", "someValue");
DDL.Items.Add(_item);

But the rendered html turns out like this:

<li>&lt;span style='color:red;'&gt; some item&lt;/span&gt;</li>

How do I alter the innerHtml of the ListItems from code behind? Or is there a better way to achieve the above?

Banana
  • 7,424
  • 3
  • 22
  • 43

1 Answers1

1

This is not possible, not because of your code or ListItem, but because you can't put html in select option.
Can I use HTML tags in the options for select elements?
Styling part of the OPTION text

Community
  • 1
  • 1
Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301