求助,关于在网页中显示一个动态表格的问题
我在.aspx.cs里面用C#写好了表格的代码,运行后网页是空的,是不是要在.aspx里面也要写代码啊???
在.aspx.cs的部分代码:
protected void Page_Load(object sender, EventArgs e)
{
//数据库连接没有问题,省略
string sqlString = "select name,sex,city from student";
SqlDataAdapter sda = new SqlDataAdapter(sqlString, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
//定义一个表格
#region
table.CellPadding = 2;//table在.aspx中定义了
table.CellSpacing = 0;
table.Width = 600;
table.Style.Add("font-size", "12");
//定义第一行
TableRow tr1 = new TableRow();
tr1.BackColor = System.Drawing.ColorTranslator.FromHtml("#CCCCCC");
tr1.BorderColor = System.Drawing.Color.Blue;
tr1.BorderStyle = BorderStyle.Solid;
tr1.BorderWidth = 1;
tr1.Style.Add("text-align", "center");
tr1.Style.Add("font-weight", "bold");
tr1.Height = 25;
//定义第一行的第一个单元格
TableCell tc1 = new TableCell();
tc1.Width = 200;
tc1.Text = "姓名";
tc1.BorderColor = System.Drawing.Color.Blue;
tc1.BorderStyle = BorderStyle.Solid;
tc1.BorderWidth = 1;
tr1.Cells.Add(tc1);
//定义第一行的第二个单元格
TableCell tc2 = new TableCell();
tc1.Width = 200;
tc1.Text = "性别";
tc1.BorderColor = System.Drawing.Color.Blue;
tc1.BorderStyle = BorderStyle.Solid;
tc1.BorderWidth = 1;
tr1.Cells.Add(tc2);
//定义第一行的第三个单元格
TableCell tc3 = new TableCell();
tc1.Width = 200;
tc1.Text = "城市";
tc1.BorderColor = System.Drawing.Color.Blue;
tc1.BorderStyle = BorderStyle.Solid;
tc1.BorderWidth = 1;
tr1.Cells.Add(tc3);
#endregion
DataView dv = ds.Tables[0].DefaultView;
for (int index = 0; index < dv.Count; index++)
{
TableRow tr2 = new TableRow();
tr2.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
tr2.BorderColor = System.Drawing.Color.Blue;
tr2.BorderStyle = BorderStyle.Solid;
tr2.BorderWidth = 1;
tr2.Style.Add("text-align", "center");
tr2.Height = 25;
//定义第一行的第一个单元格
TableCell tc4 = new TableCell();
tc4.Width = 200;
tc4.Text = dv[index]["name"].ToString();
tc4.BorderColor = System.Drawing.Color.Blue;
tc4.BorderStyle = BorderStyle.Solid;
tc4.BorderWidth = 1;
tr2.Cells.Add(tc4);
//定义第一行的第二个单元格
TableCell tc5 = new TableCell();
tc5.Width = 200;
tc5.Text = dv[index]["sex"].ToString();
tc5.BorderColor = System.Drawing.Color.Blue;
tc5.BorderStyle = BorderStyle.Solid;
tc5.BorderWidth = 1;
tr2.Cells.Add(tc5);
//定义第一行的第二个单元格
TableCell tc6 = new TableCell();
tc6.Width = 200;