How to add color to dropdownlist based on value from SQL Query Statement.

R

Rob

I want to be able to color code my dropdown list based on the status
of the users within the list. I have a SQL Query (stored Procedure)
that return the following data. (UserID, UserName, Status).

I bind the data like this from returning the data from a
SqlDataReader:

' dropdownlisting of all users
With UserList
.DataSource = GetUsersDropDown()
.DataTextField = "vcUserName"
.DataValueField = "vcUserID"
.DataBind()
.Items.Insert(0, "-- Select a User --")
.SelectedIndex = 0
End With

The GetUsersDropDown Function:

Public Function GetUsersDropDown() As SqlDataReader
Dim dr As SqlDataReader
Dim strConn = New
SqlConnection(HttpContext.Current.Application("strConn"))
Dim cmdSelect = New SqlCommand("spSOCSRListX", strConn)
cmdSelect.CommandType = CommandType.StoredProcedure
strConn.Open()
dr = cmdSelect.ExecuteReader()
Return dr
strConn.Close()
End Function



The Function returns data like (10, Joe Burns, 1). I want to be able
to identify the status (3rd column) or the user and based on the
results (1-active, 0-inactive). Color the dropdown item a either red
or white.

Please help Im getting desperate....

Many Thanks
 
A

Alvin Bruney [MVP]

You cannot color the dropdown item conditionally. There is a hack to allow
you to do this. If you care, you can replace the dropdown with a select tag.
That will allow you to customize the options somewhat.
 
E

Eran Amitai

Rob,

I don't believe there's any way to color items in a dropdownlist. If this is
really important to you you could implement an input box with a drop button
that drops down an IFrame or a positioned HTML table, but that's a lot of
work.

Eran
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top