JoeUS
asked on
Setting DropDownList.BackColor property
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.DataValueFiel d = "HtmlColor";
DropDownList.DataTextField = "HtmlColor";
DropDownList.BackColor = System.Drawing.ColorTransl ator.FromH tml("HtmlC olor");
Any Idea?
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.DataValueFiel
DropDownList.DataTextField
DropDownList.BackColor = System.Drawing.ColorTransl
Any Idea?
modify the code :
DropDownList.BackColor = System.Drawing.ColorTransl ator.FromH tml("HtmlC olor");
DropDownList.BackColor = System.Drawing.ColorTransl ator.FromH tml(<% # HtmlColor %>);
DropDownList.BackColor = System.Drawing.ColorTransl
DropDownList.BackColor = System.Drawing.ColorTransl
ASKER
You mean I can not assign back color values individually to the list elements?
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.ColorTransl ator.FromH tml("HtmlC olor");
becomes
DropDownList.BackColor = System.Drawing.ColorTransl ator.FromH tml( HtmlColor );
that doesnt make any sense.
you need to pass in a colour representation
you just need to remove the quotes:
DropDownList.BackColor = System.Drawing.ColorTransl
becomes
DropDownList.BackColor = System.Drawing.ColorTransl
do you mean you want to assign different options different colours?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.ColorTransl ator.FromH tml(<% # HtmlColor %>);
or
DropDownList.BackColor = System.Drawing.ColorTransl ator.FromH tml( HtmlColor );
DataSet that is why I need to use "HtmlColor" for the DropDownList component
These mods didn't solve the problem
DropDownList.BackColor = System.Drawing.ColorTransl
or
DropDownList.BackColor = System.Drawing.ColorTransl
what is the content of HtmlColor
if its a hex value it should be fine
if its a hex value it should be fine
are you getting errors when you try the later suggestion?
ASKER
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
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
use HtmlColor.ToString() and see if that works
ASKER
HtmlColor is a DB coulumn name and the format is correct for these two properties
DropDownList.DataValueFiel d = "HtmlColor";
DropDownList.DataTextField = "HtmlColor";
but
DropDownList.BackColor = System.Drawing.ColorTransl ator.FromH tml(HtmlCo lor.ToStri ng());
fails just like
DropDownList.BackColor = System.Drawing.ColorTransl ator.FromH tml("HtmlC olor");
DropDownList.DataValueFiel
DropDownList.DataTextField
but
DropDownList.BackColor = System.Drawing.ColorTransl
fails just like
DropDownList.BackColor = System.Drawing.ColorTransl
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
i think you need to supply a hex value in the FromHtml() method:
#ffffff - white
#000000 - black
Apresto