Create table programatically : Table « Controls « ASP.NET Tutorial

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="Default_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Table Control</title>
    <form id="form1" runat="server">
    <h1>Table Control</h1>
          <strong>Select a Font Style:</strong>
           <asp:CheckBoxList ID="cblFontStyle" runat="server" AutoPostBack="True" CellPadding="5" CellSpacing="10" RepeatColumns="3" OnInit="cblFontStyle_Init">
          <strong>Select a Font Size:</strong>
           <asp:RadioButtonList ID="rblSize" runat="server" AutoPostBack="True" CellSpacing="20" RepeatColumns="3" RepeatDirection="Horizontal">
                          <asp:ListItem text="10pt" value="10"/>  
                          <asp:ListItem text="12pt" value="12" selected = "true"/>  
                          <asp:ListItem text="14pt" value="14"/>  
                          <asp:ListItem text="16pt" value="16"/>  
                          <asp:ListItem text="18pt" value="18"/>  
                          <asp:ListItem text="24pt" value="24"/>  

     <asp:Table ID="tbl" runat="server"  BackImageUrl="Sunflower.jpg" Font-Names="Times New Roman" Font-Size="12" GridLines="Both" CellPadding="10" CellSpacing="5" HorizontalAlign="Left" Width="100%">
      <asp:TableRow HorizontalAlign="Left">
        <asp:TableHeaderCell>Font Family</asp:TableHeaderCell>
        <asp:TableHeaderCell Width="80%">Sample Text</asp:TableHeaderCell>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;        //  necessary for FontFamily
using System.Drawing.Text;      //  necessary for Fonts

public partial class Default_aspx : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e)
      string str = "The quick brown fox jumped over the lazy dogs.";
      int i = 0;

      bool boolUnder = false;
      bool boolOver = false;
      bool boolStrike = false;

      foreach(ListItem li in cblFontStyle.Items)
         if (li.Selected == true)
            switch (li.Value)
               case "u":
                  boolUnder = true;
               case "o":
                  boolOver = true;
               case "s":
                  boolStrike = true;

      int size = Convert.ToInt32(rblSize.SelectedItem.Value);

      InstalledFontCollection ifc = new InstalledFontCollection(  );
      foreach( FontFamily ff in ifc.Families )
         TableRow r = new TableRow(  );

         TableCell cFont = new TableCell(  );   
         cFont.Controls.Add(new LiteralControl(ff.Name));

         TableCell cText = new TableCell(  );
         Label lbl = new Label(  );
         lbl.Text = str;   

         lbl.ID = "lbl" + i.ToString(  );

         lbl.Font.Name = ff.Name;

         if (boolUnder)
            lbl.Font.Underline = true;
         if (boolOver)
            lbl.Font.Overline = true;
         if (boolStrike)
            lbl.Font.Strikeout = true;

         lbl.Font.Size = size;



    protected void  cblFontStyle_Init(object sender, EventArgs e)
      string[] FontStyle = {"Underline","OverLine", "Strikeout"};
      string[] Code = {"u","o","s"};

      for (int i = 0; i < FontStyle.GetLength(0); i++)
         this.cblFontStyle.Items.Add(new ListItem(FontStyle[i],Code[i]));


3.26.2.Repeater control in asp:Table
3.26.3.Dynamically adding rows to the table (C#)
3.26.4.Create table programatically
3.26.5.Dynamically adding rows to the table (VB)
3.26.6.Using the new Caption attribute (C#)
3.26.7.TableRow and TableCell