Click here to Skip to main content
15,924,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

You can do this.
C#
ListItem item = new ListItem();
item.Text = "A bold item";
item.Attributes.Add("style", "font-weight:bold");
ListBox1.Items.Add(item);
 
Share this answer
 
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[^]
 
Share this answer
 
Every item has a fontweight attribute.
So you will need to do something similar to item.Attributes.Add("style", "font-weight:bold"); via code to make this work.
 
Share this answer
 
You can try this:

ListBox1.Font.Bold=true;

hope it helps :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900