how to put color in listitems of dropdownlist?

V

Vincent

Hi,
i would like to have a background color for each listitem in the
dropdownlist which is fed with code-behind:

For i = 1 To 20
z = New ListItem("item" & i, i)
DropDownList1.Items.Add(z)
next

Thanks
Vincent
 
V

Vincent

I know, it's :
dropdownlist1.backcolor = ...
but what i want is the color in function of the value of the listitem.
i'll make a new thread.
 
L

Lloyd Sheen

Vincent said:
I know, it's :
dropdownlist1.backcolor = ...
but what i want is the color in function of the value of the listitem.
i'll make a new thread.

I use the following sub to set item styles.

Private Sub SetArtistStyle()
Dim i As Integer = 1
For i = 0 To ListOfArtists.Items.Count - 1
Dim li As ListItem = ListOfArtists.Items(i)
Select Case i Mod 2
Case 0
li.Attributes.Add("style",
"background-color:SkyBlue;color:Black")
Case 1
li.Attributes.Add("style",
"background-color:Silver;color:Black")
End Select
Next
End Sub

The code is executed after a DataBind on the dropdown. If you are not using
databinding then you can use this a version of the code in the above routine
after you create the dropdown item.

Hope this helps
Lloyd Sheen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top