I have dropdownlist that is dynamically created and contains a list of users. If the user meets a certain I apply a style attribute to highlight the user. My ListItems will all highlight correctly, except the first one on the List. This seems odd that the first will act this way and be different than the others.
ddlSupervisorList.Items(ddlSupervisorList.Items.Count - 1).Attributes.CssStyle.Value = "background:#cc66ff;"
If I select another user, the newly selected user will still maintain their highlight, but the first user will still not highlight.
I have even tried doing the following:
If ddlSupervisorList.SelectedItem.Equals(ddlSupervisorList.Items(ddlSupervisorList.Items.Count - 1)) Then
ddlSupervisorList.SelectedItem.Attributes.CssStyle.Value = "background:#cc66ff;"
End If
but it will still not highlight the first item(default item) on load.
Ultimately I went with using Some JQuery and javascript to fix the issue. I picked up the drop down list ID and got the selected option. If it was supposed to be highlighted ‘availableSelected’ was the cssclass, then I added it to the drop down list’s css for the list row.