473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do I change a listitem font color?

Do
Hi,

In my listbox, I'd like to change the color of some listitems
depending on user security.

I tried wrapping the <font color=red></font> around
my listitme's .text property, but the tags show up in the page load.

What can I do here?

Do
Nov 18 '05 #1
1 10546
Usually, you'd use something like:

ListItem MyListItem = new ListItem("text", "value");
MyListItem.Attributes.CssStyle.Add("color", "red");
MyListBox.Add(MyListItem);

However, there's a known bug in the standard ListBox and DropDownList
classes, where item attributes are ignored. To get around this, you need to
create a new class derived from the standard ListBox or DropDownList class
and override it's RenderContents method to correctly render the attributes:

override protected void RenderContents(HtmlTextWriter writer)
{
for(int c=0;c<Items.Count;c++)
{
ListItem i = Items[c];
writer.WriteBeginTag("option");
if(i.Selected) writer.WriteAttribute("selected", "selected", false);
writer.WriteAttribute("value", i.Value, true);
IEnumerator d = Items[c].Attributes.Keys.GetEnumerator();

while(d.MoveNext())writer.WriteAttribute(d.Current .ToString(),Items[c].Attri
butes[d.Current.ToString()]);
writer.Write('>');
System.Web.HttpUtility.HtmlEncode(i.Text, writer);
writer.WriteEndTag("option");
writer.WriteLine();
}
}

(The code above is from
http://groups.google.com/groups?hl=e...%40tkmsftngp05)

Hope this helps,

Mun


"Do" <do*************@hotmail.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl...
Hi,

In my listbox, I'd like to change the color of some listitems
depending on user security.

I tried wrapping the <font color=red></font> around
my listitme's .text property, but the tags show up in the page load.

What can I do here?

Do


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ACaunter | last post by:
Hi there, I was wondering if there was a way to change the font color of the text in the title bar... by default the title bar is that dark blue faiding into light blue and it has white text......
3
by: Wes McCaslin | last post by:
I have create a MDI form and a child form.I have a menu with a option to change the font color to red,blue, or yellow. but for some reason i can't figure this out. thanks wes
1
by: imartinez | last post by:
HI I am trying to change the font color and background by using system("color fg"); It gives gives me a variety of colors but it wont let me have the font and the background as the same color....
7
by: =?Utf-8?B?UmVraGE=?= | last post by:
Hi, I am trying to change the font color for the items in a dropdownlist control at run time using ASP.NET 2.0. DropDownList1.Items.Attributes.Add("style", "color:red"); But when I run the...
2
by: =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?= | last post by:
HI there. I use IE7. We have a user with bad eyesight. he cannot read the font when IE makes an input disabled (the light grey color font). I am able to change the background to a different color...
3
oll3i
by: oll3i | last post by:
how do I change input font color? thank You
0
by: jemitch0 | last post by:
I have a datagrid with a checkbox in the first column and two columns following containing text. When the checkbox is checked, I need to have the font color changed. I can get this to work fine using...
10
by: engteng | last post by:
When textbox properties enable = False the font in the textbox become gray color. How do I change the gray color to black color ? Regards, Tee
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.