表控件(Table).aspx <asp:Table ID="Table1" runat="server" CellPadding ="10" GridLines ="both" HorizontalAlign ="center" > <asp:TableRow > <asp:TableCell Text ="(0,0)"></asp:TableCell> <asp:TableCell Text ="(0,1)"></asp:TableCell> <asp:TableCell Text ="(0,2)"></asp:TableCell> </asp:TableRow> <asp:TableRow > <asp:TableCell Text ="(1,0)"></asp:TableCell> <asp:TableCell Text ="(1,1)"></asp:TableCell> <asp:TableCell Text ="(1,2)"></asp:TableCell> </asp:TableRow> </asp:Table> cs protected void Page_Load(object sender, EventArgs e) ...{ TableItemStyle tableStyle = new TableItemStyle(); tableStyle.HorizontalAlign = HorizontalAlign.Center; tableStyle.VerticalAlign = VerticalAlign.Middle; tableStyle.Width = Unit.Pixel(100); for (int i = 2; i < 10; i++) ...{ TableRow tempRow = new TableRow(); for (int j = 0; j < 3; j++) ...{ TableCell tempCell = new TableCell(); tempCell.Text = "(" + i + "," + j + ")"; tempRow.Cells.Add(tempCell); } Table1.Rows.Add(tempRow); } foreach (TableRow r in Table1.Rows) foreach (TableCell c in r.Cells ) c.ApplyStyle(tableStyle); TableHeaderCell header = new TableHeaderCell(); header.RowSpan = 1; header.ColumnSpan = 3; header.Text = "测试表格显示"; header.BackColor =Color.Red; header.Font.Bold = true; header.HorizontalAlign = HorizontalAlign.Center; header.VerticalAlign = VerticalAlign.Middle; TableRow headerRow = new TableRow(); headerRow.Cells.Add(header); Table1.Rows.AddAt(0, headerRow); }