Preferred Language:
Listing 29.5 - ColorTable.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace myControls
{
public class ColorTable : WebControl
{
protected override void RenderContents(HtmlTextWriter writer)
{
// Get list of colors
KnownColor[] colors = (KnownColor[])Enum.GetValues(typeof(KnownColor));
// Render opening table tag
writer.AddAttribute(HtmlTextWriterAttribute.Border, "1");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
// Render table body
foreach (KnownColor colorName in colors)
{
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
// Render first column
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(colorName);
writer.RenderEndTag();
// Render second column
writer.AddAttribute(HtmlTextWriterAttribute.Width, "50px");
writer.AddAttribute(HtmlTextWriterAttribute.Bgcolor, colorName.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(" ");
writer.RenderEndTag();
writer.RenderEndTag();
}
// close table
writer.RenderEndTag();
}
}
}
ASP.NET 3.5 Unleashed
- Containing almost 2,000 pages of code samples and in-depth explanation of the
ASP.NET 3.5 Framework, ASP.NET 3.5 Unleashed is the most comprehensive book
written on the ASP.NET 3.5 Framework.
ASP.NET 3.5 Unleashed is now available in your local bookstore and online (Published January 7, 2008).
All of the code samples from this book are hosted "live" at this website.
Click here
to view the table of contents and code samples.