Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 18, 2012 04:58 PM by banksidepoet
Participant
774 Points
862 Posts
Nov 17, 2012 09:06 PM|LINK
Hi,
I need some C# which says:
int maxRed = 35;
<pseudo code>
create 101 items for DDL1 (0 to 100);
colour 0 - maxRed in Red (DDL1.ForeColor = System.Drawing.Color.Red;)
colour maxRed+1 - 100 in Green;
DataBind?;
< end pseudo code>
Possible?
Contributor
4836 Points
895 Posts
Nov 17, 2012 10:39 PM|LINK
int maxRed = 35; for (int i = 1; i <= 100; i++) { ListItem newitem = new ListItem(); newitem.Value = i.ToString(); newitem.Text = "Item No. " + i.ToString(); DDL1.Items.Add(newitem); } foreach (ListItem item in DDL1.Items) { if (Convert.ToInt16(item.Value) < (maxRed + 1)) { item.Attributes.Add("style", "color: Red;"); } else { item.Attributes.Add("style", "color: Green;"); } }
All-Star
97799 Points
14494 Posts
Nov 18, 2012 09:54 AM|LINK
http://stackoverflow.com/questions/2609344/how-to-format-individual-dropdownlist-items-color-etc-during-ondatabinding-e
thanks,
Nov 18, 2012 04:58 PM|LINK
Kulrom,
That code just worked.
Thank you for taking the time to code the whole thing for me.
banksidepoet
Participant
774 Points
862 Posts
Colouring items in a DropDownList
Nov 17, 2012 09:06 PM|LINK
Hi,
I need some C# which says:
int maxRed = 35;
<pseudo code>
create 101 items for DDL1 (0 to 100);
colour 0 - maxRed in Red (DDL1.ForeColor = System.Drawing.Color.Red;)
colour maxRed+1 - 100 in Green;
DataBind?;
< end pseudo code>
Possible?
Kulrom
Contributor
4836 Points
895 Posts
Re: Colouring items in a DropDownList
Nov 17, 2012 10:39 PM|LINK
int maxRed = 35; for (int i = 1; i <= 100; i++) { ListItem newitem = new ListItem(); newitem.Value = i.ToString(); newitem.Text = "Item No. " + i.ToString(); DDL1.Items.Add(newitem); } foreach (ListItem item in DDL1.Items) { if (Convert.ToInt16(item.Value) < (maxRed + 1)) { item.Attributes.Add("style", "color: Red;"); } else { item.Attributes.Add("style", "color: Green;"); } }My Blog: ASP.NET Stuff
ramiramilu
All-Star
97799 Points
14494 Posts
Re: Colouring items in a DropDownList
Nov 18, 2012 09:54 AM|LINK
http://stackoverflow.com/questions/2609344/how-to-format-individual-dropdownlist-items-color-etc-during-ondatabinding-e
thanks,
JumpStart
banksidepoet
Participant
774 Points
862 Posts
Re: Colouring items in a DropDownList
Nov 18, 2012 04:58 PM|LINK
Kulrom,
That code just worked.
Thank you for taking the time to code the whole thing for me.