How to display all System Colors in a DataList

Platform: ASP.NET| Category: DataList

<asp:DataList id='DataList1' runat='server' >
<HeaderTemplate ><table></HeaderTemplate>
<ItemTemplate >
<tr>
	<td bgcolor =<%#Container.DataItem%> runat=server id='td'>
	<%#Container.DataItem%>
	</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:DataList>

VB.NET


Dim arrlist As New ArrayList
Dim enumColor As New KnownColor
Dim Colors As Array = [Enum].GetValues(enumColor.GetType())
Dim clr As Object
For Each clr In Colors
            If Not Color.FromKnownColor(CType(clr, KnownColor)).IsSystemColor Then
		arrlist.Add(clr.ToString())
            End If
Next 
DataList1.DataSource = arrlist
DataList1.DataBind()

C#


ArrayList arrlist = new ArrayList ();
KnownColor enumColor = new KnownColor();
Array Colors = Enum.GetValues(enumColor.GetType());
foreach(object clr in Colors)
{
	if (!Color.FromKnownColor((KnownColor)clr).IsSystemColor)
	arrlist.Add  ( clr.ToString());
}
DataList1.DataSource = arrlist;
DataList1.DataBind();

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.