Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all,

does anyone know how can I style a asp dropdownlist? The arrow of the dropdown is difficult to change, this is how it looks like initially:
http://i.stack.imgur.com/n9MFy.png[^]

Does anyone has any solution to fix or style this asp dropdownlist?
This is my code: (I could not change this into select dropdownlist because my dropdownlist options are being populated dynamically based on selection from a listbox)

ASP.NET
//asp file
            <asp:DropDownList ID="NewDropDownList" runat="server" Width="136px" OnSelectedIndexChanged="jobRun_SelectedIndexChanged" AutoPostBack="True" >  
            </asp:DropDownList>

C#
//cs file
 public void BindNewDropDownList()
        {
                        //Lost to hold the values
                        List<DateTime> listCopy = new List<DateTime>();
                        DateTime dt;
                        string values = String.Join(", ", JOBRUN_CBL.Items.Cast<ListItem>().Where(i => i.Selected).Select(i => i.Text));
                        if (values.Contains("Select All"))
                        {
                            //Loop through each items in listbox and then add it to list
                            foreach (ListItem li in ListBox1.Items)
                            {
                                if (DateTime.TryParse(li.Text, out dt))
                                {
                                    listCopy.Add(dt);
                                }
                            }
                        }
                        else
                        {
                            //Loop through each items in listbox and then add it to list
                            foreach (ListItem li in ListBox1.Items)
                            {
                                //check if item is selected
                                if (li.Selected == true)
                                {
                                    //add items to list
                                    listCopy.Add(DateTime.Parse(li.Text));
                                }
                            }
                        }

                        //compare and sort so that the latest date comes on top
                        listCopy.Sort((x, y) => y.CompareTo(x));
                        //clear the items in dropdownlist
                        NewDropDownList.Items.Clear();
                        //set the datasource to dropdownlist
                        NewDropDownList.DataSource = listCopy;
                        //set the dateformatstring in dropdownlist
                        NewDropDownList.DataTextFormatString = "{0:dd-MMM-yyyy}";
                        //Bind the dropdownlist
                        NewDropDownList.DataBind();
}


This is what I have tried but the same dropdown arrow is still there even though I added in a background image:
ASP.NET
<asp:DropDownList ID="NewDropDownList" runat="server" Width="136px" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="True" CssClass="ddl" xmlns:asp="#unknown">
           </asp:DropDownList>

C#
.ddl{
    width: 268px;
    padding: 5px;
    font-size: 16px;
    line-height: 1;
    background-color:lightblue;
    color:black;
    border-color:blue;
    border: 0;
    border-radius: 5px;
    height: 34px;
    background: url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat right lightblue;
    -moz-appearance: none; /*FF*/
    -webkit-appearance: none;  /*Chrome, Safari*/
    appearance: none;
    background-position-x: 244px;
    border:solid 1px #ddd;
}

This is the output I get currently based on what I have tried:
http://i.stack.imgur.com/n9s0C.png[^]
Please help me on this, been finding solution for this for quite sometime but still cannot find a way to decorate it.

Thanks.
Posted
Updated 27-Oct-15 21:19pm
v4
Comments
Krunal Rohit 28-Oct-15 0:34am    
So you just want to change that dropdown arrow, right ?

-KR
Member 11999641 28-Oct-15 0:36am    
Hi KrunalRohit, yup I want to change the dropdown arrow and the color of the dropdown box. Do u know any workarounds for this?
Krunal Rohit 28-Oct-15 0:42am    
Please, see my answer.

-KR
jgakenhe 28-Oct-15 0:37am    
You don't say how you want it to look. After doing a quick google https://www.google.com/?gws_rd=ssl#q=css+select+list+style I find lots of styling stuff. All you have to do is reference the css using CSSClass="yourCSS" in the control.
Member 11999641 28-Oct-15 0:59am    
Hi jgakenhe, yes I found a lot of css on Google, but they are not for asp dropdownlist. Mostly are for html dropdownlist and if I used them same arrow still exist in the asp dropdownlist.

1 solution

Well, the style of the dropdown is vendor specific. So you need to change it for all of them. See,
ASP.NET
<asp:dropdownlist id="NewDropDownList" runat="server" width="136px" cssclass="ddl" onselectedindexchanged="jobRun_SelectedIndexChanged" autopostback="True" xmlns:asp="#unknown"></asp:dropdownlist>

CSS
.ddl{
    width: 268px;
    padding: 5px;
    font-size: 16px;
    line-height: 1;
    border: 0;
    border-radius: 5px;
    height: 34px;
    background: url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat right #fff;
    -moz-appearance: none; /*FF*/
    -webkit-appearance: none;  /*Chrome, Safari*/
    appearance: none;
    background-position-x: 244px;
    border:solid 1px #ddd;
}


The bold text is important. :)
One quite good demo is here[^].

-KR
 
Share this answer
 
v3
Comments
Member 11999641 28-Oct-15 2:55am    
hi KrunalRohit, have tried on your method but the arrow still stay the same. Please look at my updated post, thanks for your help!
Krunal Rohit 28-Oct-15 3:06am    
Okay, I guess you're checking in Firefox. It was a typo mistake. I've updated the answer.

-KR
Member 11999641 28-Oct-15 3:19am    
hi KrunalRohit, I still get the same output, I am using internet explorer 9. Please look at my updated post thanks!
Krunal Rohit 28-Oct-15 3:40am    
See this: http://codepen.io/jackocnr/pen/lmAeh
Works great with IE.

-KR

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