net web form项目,我需要显示数据库中的信息。我根据我在网上做的研究编写了代码,但网页仍然没有显示数据库中的信息。 有人可以看看代码并指出错误吗? 代码如下.aspx和aspx.cs文件。如果您想查看任何其他文件代码,请与我们联系。
来自.aspx的代码
using Final_Project.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Final_Project
{
public partial class View_customers : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (SimpleFormContext context = new SimpleFormContext())
{
var customers = context.Customers.ToList();
TableRow row;
foreach (Customer c in customers)
{
row = new TableRow();
row.Cells.Add(new TableCell { Text = c.Firstname });
row.Cells.Add(new TableCell { Text = c.Lastname });
row.Cells.Add(new TableCell { Text = c.DOB });
row.Cells.Add(new TableCell { Text = c.Age.ToString() });
row.Cells.Add(new TableCell { Text = c.Gender });
row.Cells.Add(new TableCell { Text = c.Address1 });
row.Cells.Add(new TableCell { Text = c.Address2 });
row.Cells.Add(new TableCell { Text = c.City });
row.Cells.Add(new TableCell { Text = c.State });
row.Cells.Add(new TableCell { Text = c.zipcode });
row.Cells.Add(new TableCell { Text = c.email });
row.Cells.Add(new TableCell { Text = c.hear });
row.Cells.Add(new TableCell { Text = c.achieve });
row.Cells.Add(new TableCell { Text = c.plan });
}
}
}
}
}
.aspx.cs文件中的代码
do {
System.out.println(X + " bottles of beer on the wall");
System.out.println(X + " bottles of beer");
System.out.println("Take one down, pass it around");
X--;
System.out.println(X + " bottles of beer on the wall\n");
} while (X > 0);
答案 0 :(得分:3)
creating
只有not adding
行和table
。将rows
添加到table
内的loop
以显示数据。
tblCustomers.Rows.Add(row);