title: ASP.NET Dropdown Menu item color
body: <p>I have a DropDownList on an ASP.NET page that gets populated by a SQL database.</p>
  
  <pre><code>&lt;asp:DropDownList ID="ddlName" runat="server"&gt;&lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>The population is down in the code behind file:</p>
  
  <pre><code>ddlName.DataSource = SqlDataSource1;
  ddlName.DataValueField = (this.ddlName.SelectedValue);
  ddlName.DataTextField = "ccName";
  ddlName.DataBind();
  </code></pre>
  
  <p>I was wondering if it was possible to change the background or text color of an item in the list based on it's value?</p>
  
  <hr>
  
  <p>I just noticed that the example below works when the page first loads but on postback the text color disappears even though that is where the code is. Is there something I am missing?</p>
  
  <pre><code>protected override void Page_Load(object sender, EventArgs e)
      {
  
          if (!IsPostBack)
          {
  
              ddlName.DataSource = SqlDataSource5;
              ddlName.DataValueField = (this.ddlName.SelectedValue);
              ddlName.DataTextField = "ccName";
              ddlName.DataBind();
  
  
              foreach (ListItem item in ddlName.Items)
              {
                  if (item.Value == "Item 1")
                  {
                      item.Attributes.Add("style", "color:red");
                  }
  
                  if (item.Value == "Item 2")
                  {
                      item.Attributes.Add("style", "color:red");
                  }
              }
  
          }
  
      }
  </code></pre>