Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

how to put color in listitems of dropdownlist?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vincent - 07 Mar 2008 08:24 GMT
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
Vincent - 07 Mar 2008 17:53 GMT
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.

> Hi,
> i would like to have a background color for each listitem in the
[quoted text clipped - 7 lines]
> Thanks
> Vincent
Lloyd Sheen - 07 Mar 2008 18:05 GMT
>I know, it's :
> dropdownlist1.backcolor = ...
[quoted text clipped - 12 lines]
>> Thanks
>> Vincent

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
Vincent - 07 Mar 2008 21:04 GMT
Thanks,

the error was the missing ADD:
z.Attributes.Add("style", "color:red")

>>I know, it's :
>> dropdownlist1.backcolor = ...
[quoted text clipped - 36 lines]
> Hope this helps
> Lloyd Sheen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.