asp.net - 如何渲染HTML标签的列表项文本属性? [英] asp.net - How to render html tags in a ListItem text property?

查看:108
本文介绍了asp.net - 如何渲染HTML标签的列表项文本属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是通过服务器端的填充DropDownList控件。

I have a DropDownList control that is populated via server side.

我使用For Each [数据行]环路,并创建一个新的列表项

I use a For Each [datarow] loop and create a New ListItem

在DataRow的是ID为标题一栏;本场可能包含< B>或LT; I>标签。 (如[标题]上述< I> [家长标题]< / I>)

In the DataRow is a column with the ID 'Title'; this field may contain either <B> or <I> tags. (ex. "[Title] in <i>[Parent Title]</i>")

我现在面临的问题是,当我[DropDownList的] .Controls.Add([列表项]),它呈现文本字面上...所以它会显示在&lt; b>或&LT; I>标签字面上和不粗体/斜体字体。

The problem I am facing is when I [DropDownList].Controls.Add([ListItem]) it renders the text literally... so it displays the <B> or <I> tags literally and doesn't bold/italicize the font.

我曾尝试寻找所有的答案,可有人请点我朝着正确的方向?

I have tried looking all over for an answer, can someone please point me in the right direction?

推荐答案

一个DropDownList控件呈现为请在hhtml code 元素和列表项控件呈现为选项元素。一个选项元素不支持文本HTML格式。有些浏览器可以支持整个选项文本的某些造型,但没有浏览器支持的文本的一部分造型。

A DropDownList control is rendered as a select element in the hhtml code, and the ListItem controls are rendered as option elements. An option element does not support html formatting in the text. Some browsers may support some styling of the entire option text, but no browser supports styling of part of the text.

如果您需要HTML在下拉列表格式,您可能已使用DHTML,使自己更换下拉列表控件,或找到谁已经做到了。

If you need html formatting in the dropdown list, you either have to make your own replacement dropdown list control using DHTML, or find someone who has done it already.

这篇关于asp.net - 如何渲染HTML标签的列表项文本属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆