Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Different Background Colors for ListBox Items

Reply
Thread Tools

Different Background Colors for ListBox Items

 
 
gnosys@gmail.com
Guest
Posts: n/a
 
      10-17-2008
In ASP.Net 1.1 using C#, I'm trying to dynamically change the
background colors of certain listbox items based on some criteria. For
example:

[ Select Items ]
[Item 1]
[Item 2]
[Item 3 (Hot) ]
[Item 4]
[Item 5 (Hot ]

In the ListBox above, I would like the Items that are "Hot" to have a
red background. This box will obviously be populated from a dataset,
and my code time is like this:

foreach (myItem i in myItems)
{
ListItem li = myListBox.FindByValue(i.itemValue);
if (!i.IsHot)
continue;

if (li != null)
li.Attributes.CssStyle.Add("background-color", "yellow");
}

No Compilation errors, I have tried other ways to do this, didn't
work. However, if I just do ListBox.Attributes.CssStyle - it changes
the bg color of all the items. I only need to change the background of
certain items. Any help will be appreciated.
}
 
Reply With Quote
 
 
 
 
EdisonCPP
Guest
Posts: n/a
 
      10-17-2008
See if this helps:
http://www.codeproject.com/KB/custom...?display=Print

//Relevant code:
ddlMultiColor.Items[row].Attributes.Add("style",
"background-color:" + ddlMultiColor.Items[row].Value);





<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In ASP.Net 1.1 using C#, I'm trying to dynamically change the
> background colors of certain listbox items based on some criteria. For
> example:
>
> [ Select Items ]
> [Item 1]
> [Item 2]
> [Item 3 (Hot) ]
> [Item 4]
> [Item 5 (Hot ]
>
> In the ListBox above, I would like the Items that are "Hot" to have a
> red background. This box will obviously be populated from a dataset,
> and my code time is like this:
>
> foreach (myItem i in myItems)
> {
> ListItem li = myListBox.FindByValue(i.itemValue);
> if (!i.IsHot)
> continue;
>
> if (li != null)
> li.Attributes.CssStyle.Add("background-color", "yellow");
> }
>
> No Compilation errors, I have tried other ways to do this, didn't
> work. However, if I just do ListBox.Attributes.CssStyle - it changes
> the bg color of all the items. I only need to change the background of
> certain items. Any help will be appreciated.
> }



 
Reply With Quote
 
 
 
 
Göran Andersson
Guest
Posts: n/a
 
      10-18-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> In ASP.Net 1.1 using C#, I'm trying to dynamically change the
> background colors of certain listbox items based on some criteria. For
> example:
>
> [ Select Items ]
> [Item 1]
> [Item 2]
> [Item 3 (Hot) ]
> [Item 4]
> [Item 5 (Hot ]
>
> In the ListBox above, I would like the Items that are "Hot" to have a
> red background. This box will obviously be populated from a dataset,
> and my code time is like this:
>
> foreach (myItem i in myItems)
> {
> ListItem li = myListBox.FindByValue(i.itemValue);
> if (!i.IsHot)
> continue;
>
> if (li != null)
> li.Attributes.CssStyle.Add("background-color", "yellow");
> }
>
> No Compilation errors, I have tried other ways to do this, didn't
> work. However, if I just do ListBox.Attributes.CssStyle - it changes
> the bg color of all the items. I only need to change the background of
> certain items. Any help will be appreciated.
> }


Check if your code actually causes any style to be set on the <option>
tags in the resulting code.

You should know that the support for styling a select is limited, and
varies from browser to browser. Unless you are building an intranet
where you can impose the usage of a specific browser, you should only
use the style as a visual aid, i.e. also change the actual text of the
item to make sure that all users can see the status.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy ListBox items to anoher listbox Tomas ASP .Net 1 08-12-2008 08:22 AM
Tkinter Listbox - Different Text colors in one listbox rahulnag22@yahoo.com Python 6 05-31-2007 06:48 AM
Listbox move multiple selected items to second listbox K B ASP .Net 2 01-08-2007 11:16 AM
Re: Listbox with colors as items Ken Cox [Microsoft MVP] ASP .Net 0 05-14-2004 12:19 PM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM



Advertisments