I would like to be able to change the color of the text of items in a webdropdown before the drop down is displayed. The change in color would be based on a certain condition of the item that is being shown in the drop down list. So some items would be shown in one color and other items in a different color, based on the condition. My drop down is bound to a SQL data source in a Visual Basic application. I am using framework 4.0. What event would I use to do this and how do I access each item, while it is being loaded.
Thank you.
What you have described above works, but I cannot seem to be able to set the text color. What is demonstrated in the code is 'background color'. Any ideas how to do that?
Hello Cathy,
One way to do that is with little css and C#\VB code
You can define your css class in external file and then in code - behind to decide which one where to be applied :
<style type="text/css">
.testCss
{
background-color : Red;
}
</style>
protected void Page_Load(object sender, EventArgs e)
this.WebDropDown1.DataSource = MakeTable();
this.WebDropDown1.DataBind();
for (int i = 0; i < this.WebDropDown1.Items.Count; i++)
if (i == 2)
this.WebDropDown1.Items[i].CssClass = "testCss";
Hope that helps