C#建Table

  • 10692
  • 0
  • C#
  • 2016-06-29

摘要:C#建Table


Table tb = new Table();
        tb.Attributes.Add("Border", "1");
        tb.Width = 100;
        tb.Height = 20;
        tb.ID = "Test";
        TableRow tr = new TableRow();
        TableCell tc = new TableCell();
        tc.ColumnSpan = 2;
        tc.Style[HtmlTextWriterStyle.TextAlign] = "center"; //置中
        Label lbl = new Label();
        lbl.GetType().GetProperty("Text").SetValue(lbl, "Table", null);
        tc.Controls.Add(lbl);
        tr.Cells.Add(tc);
        tb.Rows.Add(tr);
        TableRow tr1 = new TableRow();
        TableCell tc1 = new TableCell();
        Label lbl1 = new Label();
        lbl1.GetType().GetProperty("Text").SetValue(lbl1,"cell1",null);
        tc1.Controls.Add(lbl1);
        TableCell tc2 = new TableCell();
        Label lbl2 = new Label();
        lbl2.GetType().GetProperty("Text").SetValue(lbl2, "cell2", null);
        tc2.Controls.Add(lbl2);
        tr1.Cells.Add(tc1);
        tr1.Cells.Add(tc2);
        tb.Rows.Add(tr1);
        this.Controls.Add(tb);