CheckBoxList

G

Giuseppe Vitalone

Hi all! I'm new on this newsgroup... I'm Italian, so don't be angry if mY
english isn't perfect! :D
Is it possible to associate a color to a ListItem in a CheckBoxList?
Thanks all
 
K

Ken Cox [Microsoft MVP]

Hi Giuseppe,

You can set the colour using a style when you set the text. Here's an
example that is fun to watch:


Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
Dim strSelectedColor As String
Dim li As ListItem
Dim lit1 As Literal
Dim lit2 As Literal
Dim enumColor As New KnownColor
Dim Colors As Array = _
[Enum].GetValues(enumColor.GetType())
Dim colour As KnownColor
For Each colour In Colors
li = New ListItem
li.Text = "<SPAN STYLE='color:" & _
colour.ToString & ";'>" & _
colour.ToString & "</SPAN>"
li.Value = colour.ToString
CheckBoxList1.Items.Add(li)
Next
End If
End Sub

<asp:CheckBoxList id="CheckBoxList1" runat="server"></asp:CheckBoxList>

Ken
Microsoft MVP [ASP.NET]
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top