Conditional style in DropDownList

M

Malin

Hi,

I want to have conditional style in my databound DropDownList.
Depending on the value I want it to be either black or red. Is it
possible?
I don't want to write my own control.

Thanks,
Malin
 
K

Ken Cox [Microsoft MVP]

Hi Malin,

You could change the color or CssClass based on the current selection:

Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles _
DropDownList1.SelectedIndexChanged
DropDownList1.BackColor = _
Color.FromName(DropDownList1.SelectedValue.ToString)
DropDownList1.CssClass = _
DropDownList1.SelectedValue.ToString
End Sub

Does this help?

Ken
MVP [ASP.NET]

--

Important: Patch Windows *beyond* Blaster.
http://www.microsoft.com/technet/security/bulletin/MS03-039.asp


Hi,

I want to have conditional style in my databound DropDownList.
Depending on the value I want it to be either black or red. Is it
possible?
I don't want to write my own control.

Thanks,
Malin
 
M

Malin

Thanks for the post, but unfourtunately this was not what I was after.
I would like to have different styles for the different <option>
elements. Like this:

<select>
<option style="color: black">period 4 (open)
<option style="color: black">period 3 (open)
<option style="color: red">period 2 (closed)
<option style="color: red">period 1 (closed)
</select>

This makes the items look different when you "pull the curtain".

/Malin
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top