【问题标题】:DropDownList Items with Html content具有 Html 内容的 DropDownList 项目
【发布时间】:2015-02-14 15:24:01
【问题描述】:

所以我从后面的代码向DropDownList 添加项目,我需要这些项目具有 html 内容。

我添加的项目如下:

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

但是渲染出来的html是这样的:

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

如何从后面的代码中更改 ListItems 的 innerHtml?或者有没有更好的方法来实现上述目标?

【问题讨论】:

    标签: c# html asp.net


    【解决方案1】:

    这是不可能的,不是因为你的代码或ListItem,而是因为你不能把html放在select选项中。
    Can I use HTML tags in the options for select elements?
    Styling part of the OPTION text

    【讨论】:

    • 我明白了,谢谢。有什么解决方法可以实现吗?
    • 我认为您将需要搜索自定义下拉菜单,该下拉菜单会呈现其他内容而不是选择选项
    猜你喜欢
    • 2016-10-25
    • 2013-10-07
    • 1970-01-01
    • 2016-10-01
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多