soft_coder 0 Light Poster

Hi!

I want to set the style of individual items in an asp:dropdownlist. The item may be disabled/enabled.

My immediate requirement is to set the style of an individual item in a dropdown which is disabled.

ddlCategory.DataSource = dtCategory;
ddlCategory.DataTextField = "CategoryName";
ddlCategory.DataValueField = "CategoryID";
ddlCategory.DataBind();

The above piece of code is for binding and the next code snippet is Dropdownlist OnDataBound event.

protected void ddlCategory_DataBound(object sender, EventArgs e)
        {
            foreach (ListItem lstItem in ddlCategory.Items)
            {
                if (lstItem.Value == "title")
                {
                    lstItem.Attributes.Add("style", "color: #000000; font-weight: bold;");
                    lstItem.Attributes.Add("disabled", "disabled");
                }
            }
        }

I am using the above. For some reason I the style is not applying but the particular item is disabled.
I don't know where I am going wrong.

Any kind of help will be appreciated. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.