Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Setting DropDownList.BackColor property

Posted on 2006-07-17
15
Medium Priority
?
754 Views
Last Modified: 2008-03-04
Hi
I am trying to set the back color of a dropdownlist but giving me an incorrect format error

the format is the usual (#FF0000) Etc
           
 DropDownList.DataValueField = "HtmlColor";
 DropDownList.DataTextField = "HtmlColor";          
 DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml("HtmlColor");

Any Idea?
0
Comment
Question by:JoeUS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17122439
Hi JoeUS,

i think you need to supply a hex value in the FromHtml() method:

#ffffff - white
#000000 - black

Apresto
0
 
LVL 7

Expert Comment

by:skvikram
ID: 17122457
modify the code :
DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml("HtmlColor");

DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml(<% # HtmlColor %>);

0
 

Author Comment

by:JoeUS
ID: 17122465
You mean I can not assign back color values individually to the list elements?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:apresto
ID: 17122477
i dont think so

that doesnt make any sense.

you need to pass in a colour representation

you just need to remove the quotes:

DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml("HtmlColor");

becomes

DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml( HtmlColor );
0
 
LVL 23

Expert Comment

by:apresto
ID: 17122482
do you mean you want to assign different options different colours?
0
 
LVL 7

Accepted Solution

by:
brdrok earned 1200 total points
ID: 17122905
check out the following link:

http://www.codeproject.com/aspnet/ColorListBox.asp

it might be able to point you in the right direction.

0
 

Author Comment

by:JoeUS
ID: 17122908
this code is in C# and on the code behind page. I am loading the values from a

DataSet that is why I need to use "HtmlColor" for the DropDownList component

These mods didn't solve the problem

DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml(<% # HtmlColor %>);
or
DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml( HtmlColor );

0
 
LVL 23

Expert Comment

by:apresto
ID: 17123011
what is the content of HtmlColor

if its a hex value it should be fine
0
 
LVL 23

Expert Comment

by:apresto
ID: 17123019
are you getting errors when you try the later suggestion?
0
 

Author Comment

by:JoeUS
ID: 17123205
The HtmlColor value is formated like this #FFFFFF and it of course changes with each listItem
The later suggestion gives me an out of context error. It seems like the DropDownList component can't process DataSet fields for background color. It does do fine when I give it a hard coded value (HEX #FF0000) but it doesn't take the same value from the DataSet
0
 
LVL 23

Expert Comment

by:apresto
ID: 17123279
use HtmlColor.ToString() and see if that works
0
 

Author Comment

by:JoeUS
ID: 17125311
HtmlColor is a DB coulumn name and the format is correct for these two properties
DropDownList.DataValueField = "HtmlColor";
DropDownList.DataTextField = "HtmlColor";
but
DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml(HtmlColor.ToString());
fails just like
DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml("HtmlColor");
0
 
LVL 23

Assisted Solution

by:apresto
apresto earned 400 total points
ID: 17128404
Ok...

in the FromHtml() you need to have a colour in this format #xxxxxx.  

By using "HtmlColor" you are just passing in text, so this is wrong
By passing in HtmlColor (without quotes) this represents a variable - what is in this variable?

try this and see if it works:

DropDownList.BackColor = System.Drawing.ColorTranslator.FromHtml("#ff0000");

and just see if it takes effect
0
 
LVL 7

Assisted Solution

by:skvikram
skvikram earned 400 total points
ID: 17128905
Htmlcolor is a variable which can be assigned to
DropDownList.DataValueField = "HtmlColor";
DropDownList.DataTextField = "HtmlColor";

but it should be converted to suitable hexcolor value type before it can be passed to System.Drawing.ColorTranslator.FromHtml() LIKE in this code

System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml( Htmlcolor );
DropDownList.BackColor = c;

Any Hex color value cannot be passed to BackColor property it has to be ARGB Value. like
Color [A=255, R=245, G=247, B=248]
0
 

Author Comment

by:JoeUS
ID: 17130062
I have found the solution and it was "brdrok" who pointed me to the right direction
Here is the link to achieve what I was looking for and some explanation why
DropdownList color properties don't do so well in a DataBind situation. I also apreciate
"apresto" and  "skvikram" comments and efforts to trubleshoot this MS Bug.

http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question