if (!this.IsPostBack)
{ Table Table1 = new Table(); AddRow(Table1, "姓名", "专业", "所在学样", "个人网站"); AddRow(Table1, "小明", "计算机系", "吉林大学", "http://www.mingrisoft.com"); Page.Controls.Add(Table1); }
public void AddRow(Table Table1, string strName1, string strName2, string strName3, string strName4)
{ TableRow row = new TableRow(); //第一行第1列 TableCell cell1 = new TableCell(); cell1.Font.Size = FontUnit.Small;//设置单元格的字体大小 cell1.Text = strName1; //设置单元格中显示的文本 cell1.Width = 80; //设置单元格的宽度 row.Cells.Add(cell1); //将创建的单元格添加到行对象 //第一行第2列 TableCell cell2 = new TableCell(); cell2.Font.Size = FontUnit.Small; cell2.Text = strName2; cell2.Width = 80; row.Cells.Add(cell2); //第一行第3列 TableCell cell3 = new TableCell(); cell3.Font.Size = FontUnit.Small; cell3.Text = strName3; cell3.Width = 80; row.Cells.Add(cell3); //第一行第4列 HyperLink hyperLink = new HyperLink(); hyperLink.Text = strName4; hyperLink.NavigateUrl = strName4; hyperLink.Target = "_top"; TableCell cell4 = new TableCell(); cell4.Font.Size = FontUnit.Small; cell4.Controls.Add(hyperLink); cell4.Width = 240; row.Cells.Add(cell4); Table1.Rows.Add(row); }