我想从数据库中显示数据集。我的目标是使用VS 2005在每行5天的aspx页面上显示一个月的数据。我写了这样的代码,但我与我和j混淆。此代码不显示任何内容在代码隐藏中创建表格并显示文本框
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
Table table = new Table();
table.ID = "Table1";
TableRow row = new TableRow();
TableCell cell = new TableCell();
TextBox tb1 = new TextBox();
TextBox tb2 = new TextBox();
// I am not sure what i and j should be here to display 5 per each row..
for (int i = 0; i < 5; i++)
{
if (int j == 0; j < ds.Tables[0].Rows.Count; j ++)
{
tb1.ID = "txtDateRow" + x + "Col" + j;
tb1.Text = ds.Tables[0].Rows[x]["Date"].ToString();
tb2.ID = "txtDetails" + x + "Col" + j;
tb2.Text = ds.Tables[0].Rows[x]["AmountSold"].ToString();
cell.Controls.Add(tb1);
cell.Controls.Add(tb2);
table.Rows.Add(row);
}
}
Panel1.Controls.Add(table);
}
如果有人可以帮助我解决这个问题,我真的很感激。非常感谢。
“j”在哪里声明/初始化? – Akhil 2012-01-30 20:16:28
它显示“nothing”还是显示没有行的table元素?这两个是非常不同的结果。 – David 2012-01-30 20:17:37
为什么'table'被添加到'Page.Form.Controls'和'Panel1.Controls'? – David 2012-01-30 20:20:31