编程代码中列表框中的粗体文本
问题描述:
你好.
我正在做一个网站,想在代码部分的列表框中将字体的粗细更改为粗体.
我需要在运行时从代码中添加不同的值,并希望将一个单词加粗.
有帮助吗?
Hi there.
Im doing a website and would like to change the font-weight to bold in a listbox from the code section.
I need to add different values from the code during runtime and would like to bold a single word.
Any help?
答
您可以执行此操作.
You can do this.
ListItem item = new ListItem();
item.Text = "A bold item";
item.Attributes.Add("style", "font-weight:bold");
ListBox1.Items.Add(item);
您需要编写一个自定义控件,使您可以在列表项中使用HTML(显然,要使其在所有浏览器中都能正常工作是很困难的).我知道有很多控件可以买,如果你想走那条路的话.这是一个:
http://easylistbox.com/demoCustomized.aspx [
You need to write a custom control that lets you use HTML in the list items (evidently, it''s difficult to make it work under all of the browsers). I know there are controls out there you can buy if you want to go that route. Here''s one:
http://easylistbox.com/demoCustomized.aspx[^]
每个项目都有fontweight属性.
因此,您将需要通过代码执行与item.Attributes.Add("style", "font-weight:bold");
类似的操作才能使其正常工作.
Every item has a fontweight attribute.
So you will need to do something similar toitem.Attributes.Add("style", "font-weight:bold");
via code to make this work.