473,386 Members | 1,679 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,386 software developers and data experts.

Different Background Colors for ListBox Items

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.
}
Oct 17 '08 #1
2 11090
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);

<gn****@gmail.comwrote in message
news:f5**********************************@v13g2000 pro.googlegroups.com...
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.
}

Oct 17 '08 #2
gn****@gmail.com 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
Oct 18 '08 #3

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

Similar topics

4
by: Scott | last post by:
There is a setting in IE for "Print background colors and images." I've noticed that without checking this option, a web page will print CSS lines between table rows, but a background color of...
3
by: Bob - Andover, MA | last post by:
I know how to define a background color for the entire page, and for a table, and even using style sheets and 'P CLASS=...' for changing paragraph background colors. However, I'd like to be able...
16
by: J. B. Moreno | last post by:
I read the faq, and it mentions that IE 4 on windows requires setting a printing option to allow background colors to be printed. Things change, life goes on, other browsers come into...
4
by: Franklin | last post by:
WITHOUT KNOWING ANYTHING ABOUT THE CURRENT COLORS, I want to swap the foreground/background colors of a link when someone hovers over it. Is this possible with HTML, CSS, DOM, & JavaScript? If...
6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
3
by: Baren | last post by:
Hi! I have a generalized Stored Procedure to get the listbox items in a datareader.Then i am binding the datareader to the listbox. For different pages and different conditions i need to hide...
2
by: PeterW | last post by:
Hi everybody, I know this issue has already been posted by others and I viewed all the threads dealing with it, but I still couldn't find the whole answer to my problem. So here we go: I have...
1
by: Refugnic | last post by:
I tried to fill a ListBox with a DataSource pointing to an ArrayList. It all works fine...up to one point. The ArrayList is dynamic, which means the contents of it change, during the course of...
1
by: divya | last post by:
Hello, I used the below code to move selected items between two listboxes Left and Right:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPopup.aspx.cs" Inherits="TestPopup" %> ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.