我在.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;
tc6.Text = dv[index]["city"].ToString();
tc6.BorderColor = System.Drawing.Color.Blue;
tc6.BorderStyle = BorderStyle.Solid;
tc6.BorderWidth = 1;
tr2.Cells.Add(tc6);
} }
.aspx中的部分代码:
<head runat="server">
<title></title>
<style type="text/css">
#form1
{
height: 111px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:Table ID="table" runat="server" Height="100px" Width="511px">
</asp:Table>
</form>
</body>
</html>
是不是还要在.aspx中写什么???
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;
tc6.Text = dv[index]["city"].ToString();
tc6.BorderColor = System.Drawing.Color.Blue;
tc6.BorderStyle = BorderStyle.Solid;
tc6.BorderWidth = 1;
tr2.Cells.Add(tc6);
} }
.aspx中的部分代码:
<head runat="server">
<title></title>
<style type="text/css">
#form1
{
height: 111px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:Table ID="table" runat="server" Height="100px" Width="511px">
</asp:Table>
</form>
</body>
</html>
是不是还要在.aspx中写什么???
解决方案 »
- 如何批量给button添加事件,且事件里头的变量是由button同级的控件传过来的
- net 虚拟内存高
- 我在一个页面上给Profile的属性附了值,在另一个页面读不到是怎么回事?
- 中国葡萄酒资讯网诚聘ASP.NET程序员
- 在线给分!为什么用了iframe的网页不能够再放控件了?
- 老大出马啊~~我这段JS要在vb.net中写,麻烦帮我转换一下,谢谢了
- 如何生成word文档,供下载
- 请问怎么样实现用一个datareader绑定到两个DropDownList上???在线等待!
- 通过注册页面按钮打开新页面,选择新页面中gridview中checkbox,选择好后,将选择的值传回注册页面的文本框。望各位大大好心帮助~
- 怎么在一个自定义类中调用另一个自定义类中的函数?
- 数据库用什么方式存文章和视频啊!
- 如何让局域网用户访问我的ASP.NET网站?
//所有的行都要添加到table中,例
table.Rows.Add(tr1);