"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Tuesday, October 4, 2011

Change the font color based on the value in dropdownlist in asp.net c#

 Hi *.*,
2day i'm showing some css magic on dropdown list.
demo
 
How to Implement?

On html


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Change the font color based on the value in dropdownlist in asp.net c#</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:DropDownList ID="ddpdown" runat="server" >
    </asp:DropDownList>
    </div>
    </form>
</body>
</html>
 

 On Server Side


   protected void Page_Load(object sender, EventArgs e)
    {
        for (int _i = 0; _i < 10; _i++)
        {
           
            if (_i <5)
            {
                ddpdown.Items.Add(_i.ToString()+" - Not Avilable");
                ddpdown.Items[_i].Attributes.CssStyle.Add("color", "red");
            }
            else
            {
                ddpdown.Items.Add(_i.ToString()+" - Avilable");
                ddpdown.Items[_i].Attributes.CssStyle.Add("color", "green");
            }
           
        }
    }
 
Hope u got it...
Stay Tune...
Have a nice day... 'N happy Coding :)

No comments: