CodeSnip: Changing the Color of a List Item's Text at Run-Time with Visual Basic 2005
page 2 of 5
by Shaun Eutsey
Feedback
Average Rating: 
Views (Total / Last 10 Days): 25415/ 126

Call to the database.

Listing 1

Dim CONNECTION_STRING As String = _
 "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True"
 
Dim sQuery As String = _
 "select TerritoryID, TerritoryDescription, RegionID from Territories"
 
Dim dr As SqlDataReader
Dim cn As New SqlConnection(CONNECTION_STRING)
Dim cmd As New SqlCommand(sQuery, cn)

The fun begins when we actually call the cmd.executereader.

Listing 2

cn.Open()
dr = cmd.ExecuteReader
 
Do While dr.Read
    Dim li As New ListItem _
 (dr("TerritoryDescription"), dr("TerritoryID"))
    Select Case dr("RegionID")
    Case 1
      li.Attributes.Add("style", "color:red")
    Case 2
      li.Attributes.Add("style", "color:Green")
    Case 3
      li.Attributes.Add("style", "color:Dodgerblue")
    Case Else
      li.Attributes.Add("style", "color:orange")
    End Select
    ddlTerritories.Items.Add(li)
Loop
cn.Close()

View Entire Article

User Comments

Title: Thanks for the help!   
Name: mike
Date: 2009-07-14 9:07:21 AM
Comment:
Seriously saved me alot of time!
Title: Mr   
Name: Dean White
Date: 2008-01-25 4:44:26 AM
Comment:
You are a scolar and a Gentleman
Thank you.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-05-20 8:48:42 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search