Click here to Skip to main content
15,906,333 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
how to highlight first value from Dropdownlist in asp.net,

I bind a some values in my Dropdownlist .i need a highlight(different colour) 1st item Dropdownlist .How to do it.any one can help me. Thank You
Posted

Try this

XML
<style type="text/css">

       option.red
       {
           background-color: red;
       }
       option.blue
       {
           background-color: blue;
       }
       option.white
       {
           background-color: white;
       }

   </style>


XML
<select>
            <option value="item 1" class="red">Item 1</option>
            <option value="item 2" class="blue">Item 2</option>
            <option value="item 3" class="white">Item 3</option>
        </select>


is this sane u r looking for
 
Share this answer
 
Comments
[no name] 28-Nov-13 1:52am    
yes.but this one is not working
Try the below code

dropdownlist1.Items[0].Attributes.Add("style","background-color:Red");


hope this helps...
 
Share this answer
 
v2
Hi,

Please set background color as you want in option. and based on option selection you have to change background color of dropdown(select) also. Because option and select control are different. So with the help of javascript/Jquery you can manage BG color of option and select box.

Hope this will help
 
Share this answer
 
U can use jquery with a simple function.


$(function(){

$('select').bind('change',function()){
$(this option:selected).css('background-color','red');
});

});


This will solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900