Thanks!! This worked well. I ended up using the following code to create
an HtmlTable instance and add it to a placeholder control on my page:
HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;
KnownColor enumColor = new KnownColor();
Array colors = Enum.GetValues(enumColor.GetType());
bool bFirstColorFound = false;
for (int i = 0; i < colors.Length; i++)
{
string strColor = colors.GetValue(i).ToString();
if ( strColor == "AliceBlue")
{
bFirstColorFound = true;
}
if (bFirstColorFound == true)
{
htr = new HtmlTableRow();
//FIRST CELL
htc = new HtmlTableCell();
htc.InnerText = strColor ;
htr.Cells.Add(htc);
//SECOND CELL
htc = new HtmlTableCell();
htc.BgColor = strColor;
htc.InnerHtml = @" ";
htr.Cells.Add(htc);
//Add row to table.
ht.Rows.Add(htr);
}
}
phColors.Controls.Add(ht);
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:en****************@TK2MSFTNGP12.phx.gbl...
Here's some code I use that might give you a hand:
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 New ListItem
Dim enumColor As New KnownColor
Dim Colors As Array = _
[Enum].GetValues(enumColor.GetType())
DropDownList1.DataSource = Colors
DropDownList1.DataBind()
strSelectedColor = DropDownList1.Items(0).Text
li.Value = 0
li.Text = "--ALL"
DropDownList1.Items.Insert(0, li)
End If
End Sub 'Page_Load
Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Label1.Text = DropDownList1.SelectedItem.Text
End Sub
Ken
Microsoft MVP [ASP.NET]
"Mark" <fi******@idonotlikejunkmail.umn.edu> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl... Is there a programatic way to iterate through all the named colors?
Something like:
HtmlTable ht = new HtmlTable();
HtmlTableRow htr;
HtmlTableCell htc;
foreach (Color c in [collection of all colors]) //I CAN'T FIND
COLLECTION OF
ALL COLORS
{
htr = new HtmlTableRow();
htc = new HtmlTableCell();
htc.InnerText = c.Name;
htr.Cells.Add(htc);
ht.Rows.Add(htr);
}
phColors.Controls.Add(ht); //Display table in a placeholder control
Thanks in advance!
Mark