Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

The following snippet below describes on how we are going to set the ListItem Background Color based on the Color name displayed in the DropDownList


ASPX MARKUP OF DROPDOWNLIST


<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" OnLoad="DropDownList1_Load">
        <asp:ListItem Value="-1">Select</asp:ListItem>
        <asp:ListItem Value="0">Red</asp:ListItem>
        <asp:ListItem Value="1">Blue</asp:ListItem>
        <asp:ListItem Value="2">Green</asp:ListItem>
        <asp:ListItem Value="3">Violet</asp:ListItem>
</asp:DropDownList>

RELEVANT CODES
protected void DropDownList1_Load(object sender, EventArgs e)
{
        for (int i = 0; i < DropDownList1.Items.Count; i++)
        {
            DropDownList1.Items[i].Attributes.Add("style", "background-color:" + DropDownList1.Items[i].Text);
           
        }
}

That's it!

Technorati Tags: ,
Posted on Friday, September 12, 2008 2:10 AM ASP.NET , Tips&Tricks | Back to top


Comments on this post: Set Background Color for each ListItems of the DropDownList

# re: Set Background Color for each ListItems of the DropDownList
Requesting Gravatar...
This worked just fine, thank you...
Left by Jorge Recinos on Jun 03, 2011 5:52 AM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net