Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4609112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:56:26+00:00 2026-05-22T00:56:26+00:00

I have a dropdown list in my C# / .NET project that is on

  • 0

I have a dropdown list in my C# / .NET project that is on a child page (within a Master page).

I am applying the jQuery selectmenu styling via the master page:

$(function () {
   $('select[id*="lstClients"]').selectmenu({ style: 'dropdown', maxHeight: 150 });
});

I need to give certain items in the dropdown a different background colour.

e.g. if ClientX has Y number of projects then set the background colour to red or something like that.

I have all of the data/counters being populated via the code-behind so basically what I am asking is if anyone knows how I can change the background colour of certain items in the dropdown via jQuery?

Pseudo-code:

If ddl.Item.value > 0
 set bgColor = black
Else
 set bgColor = white

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:56:27+00:00Added an answer on May 22, 2026 at 12:56 am

    I think jQuery UI SelectMenu will honour a background-color for an option (it certainly worked when I fiddled with it briefly on here.

    So, given that, you could do something like this. I’ve used a List<Pair> as an example datasource as you didn’t mention what your source data was. ddlItems is the ID of the DropDownList.

    List<Pair> items = new List<Pair>();
    items.Add(new Pair("zero", "0"));
    items.Add(new Pair("one", "1"));
    items.Add(new Pair("two", "2"));
    
    foreach (Pair item in items)
    {
        ListItem li = new ListItem();
        li.Text = item.First.ToString();
        li.Value = item.Second.ToString();
        li.Attributes.CssStyle.Add("background-color", (int)item.Second > 0 ? "black" : "white");
        ddlItems.Items.Add(li);
    }
    

    I must admit I haven’t had chance to test this fully, but that should hopefully work for you. You could probably do the same thing using a class, eg: Attributes.Add("class", "greaterThanZero"); which would avoid the inline styles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an asp.net-mvc webpage and i want to show a dropdown list that
I have an ASP.NET DropDownList control that renders into a dropdown list (select HTML
I have the following scenario: My page has a dropdown list that allows user
i have an asp.net mvc page and i want to have a dropdown list
I have state and city dropdown list in an ASP.NET 3.5 application. However, I
MVC 3 razor VB.NET project. I have resorted to manual building a list for
I've got a project that uses a Master Page. There is also a Content
Hi All I need a CheckBox Dropdown list control in asp.net i have seen
I have a dropdown list of peoples names that is quite long. As many
I have a Dropdown List in the asp page which I bind it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.