Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 3rd, 2003, 08:08 PM
Authorized User
 
Join Date: Oct 2003
Location: , , Norway.
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default listbox, different color for each item?

Hi all,
I was just wondering if it's possible to change the text color or background color for an item in a listbox? Eks. you have an SQL querry string that gets some values. If one of the values is 1 then the color is normal. If the value is 2 then the color turns red! Is this possible?

***************MY CODE FOR FILLING THE LISTBOX********
    Sub FillList(ByVal Level As Int32, ByVal SQL1 As String)
        Dim SQ As Data.SqlClient.SqlDataReader
        Dim SQLConnect As Data.SqlClient.SqlConnection
        SQLConnect = SQL.Connect
        Dim SQLCmd As New System.Data.SqlClient.SqlCommand("set dateformat dmy", SQLConnect)
        ListColl(Level).Items.Clear()
        Try
            SQLCmd.CommandText = (SQL1)
            SQ = SQLCmd.ExecuteReader()
            Dim i As Integer
            Do While SQ.Read = True
                If SQ.GetString(0).Trim <> "" Then ListColl(Level).Items.Add(SQ.GetString(0))
            Loop
            SQ.Close()
        Catch ex As Exception
            Response.Write("Fill list: " & ex.Message)
        End Try
        SQLCmd.Connection.Close()
        SQLConnect.Close()
    End Sub
************END CODE*********************

I need something like this:
************CODE FROM ABOVE*********
Do While SQ.Read = True
If SQ(2) = 1 then
If SQ.GetString(0).Trim <> "" Then ListColl(Level).Items.Add(SQ.GetString(0))
else
*Some Color setting for that item*
If SQ.GetString(0).Trim <> "" Then ListColl(Level).Items.Add(SQ.GetString(0))
end if
Loop
***************END******************

Thanks for any help I can get on this!

------------------------
All help is Good help!
Regards
Michael
__________________
------------------------
All help is Good help!
Regards
Michael
Reply With Quote
  #2 (permalink)  
Old November 13th, 2003, 10:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Sydney, NSW, Australia.
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Create a new ListItem. Set the cssClass to the appropriate CSS class that you want to use. Then add this ListItem to your DropDownList's Items collection. So you should end up with:

<option class="itemA">Some Value</option>
<option class="itemB">Some Other Value</option>

and then in your CSS file (or inline) you have:

itemA
{
   color: #FF0000;
}
itemB
{
   color: #00FF00;
}

Cheers
Ken



Microsoft MVP - Windows Server (IIS)
www.adOpenStatic.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change only the first item in array's back color i remya1000 .NET Framework 1.x 1 November 5th, 2007 10:43 PM
ListBox Item selection caterpillar ASP.NET 1.0 and 1.1 Professional 1 July 26th, 2006 12:50 PM
Select an particular item when a listbox opens? alastair Access 2 December 29th, 2005 06:04 PM
One item in Listbox venterjo General .NET 2 February 1st, 2005 05:45 AM
How to get selected Item from Listbox? Iceman571 ADO.NET 1 March 25th, 2004 06:33 AM



All times are GMT -4. The time now is 08:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.