Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in this list i want to add red color to my string Telugu and make it as unselectable
thanks in advance

XML
List<CascadingDropDownNameValue> list = new List<CascadingDropDownNameValue>();

               string[] singlemoviedetails = null;

               list.Add(new CascadingDropDownNameValue("TELUGU", "TELUGU"));


               foreach (string single_moviedetails in total_moviedetails)
               {
                   singlemoviedetails = single_moviedetails.Split('~');


                   if ("TELUGU".Equals(singlemoviedetails[2].ToString()))
                   {

                       list.Add(new CascadingDropDownNameValue(singlemoviedetails[1].ToString(), singlemoviedetails[0].ToString()));
                      

                       
                     

                   }//if
               }
Posted
Comments
teja sai ravi 19-Nov-13 1:46am    
please help me how can i add colors to my list items in my cascading dropdown list
JoCodes 19-Nov-13 1:48am    
You want to add color for all the Listitems in the dropdown list or only some of those?
teja sai ravi 19-Nov-13 2:06am    
thanks for ur reply friend.. for some of them only.
JoCodes 19-Nov-13 2:08am    
Have you tried the Databound event of the dropdown?
JoCodes 19-Nov-13 2:16am    
Have added a solution ... can you try and revert ?

You can use the Databound event of the Dropdownlist for changing the color of the item.

Try something like
C#
protected void DropDownList1_DataBound(object sender, EventArgs e)
        {
            foreach (ListItem item in DropDownList1.Items)
            {               
               
                if (string.Compare(item.Text, "Telugu",true)==0)//change the condition 
                { 
                    item.Attributes.Add("style", "background-color:#110001");//apply any style as your need
                    item.Selected = false;// Or enabled false as per your need
                }
            }
        }


Hope this helps...
 
Share this answer
 
Comments
teja sai ravi 19-Nov-13 2:22am    
hi friend i tried like this but it is giving error as object reference not set to value why because bindig is done in webmethod in asmx page
JoCodes 19-Nov-13 2:27am    
Can you show the code?It shouldnt be a problem since this dropdown should be bound on selection of parent dropdown , right?
teja sai ravi 19-Nov-13 2:35am    
yes friend but data bound event also not firing i think for data bounding it will go to web method in asmx page..
i solved it by writing in javascript as follows...

XML
<script type="text/javascript">
    function setcolor(ddl) {
        for (i = 0; i < ddl.options.length; i++) {
            if (ddl.options[i].value == "TELUGU") {
                ddl.options[i].style.color = "red";
                ddl.options[i].disabled = "disabled";

            }
}
}

<asp:dropdownlist id="dropmovie" runat="server" class="ddl" onclick="setColor(this);" style="width:210px; height:30px; background-color:#40E0D0" xmlns:asp="#unknown"></asp:dropdownlist>
 
Share this answer
 
v2

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