我正在尝试应用于Eval
一个简单的表(在 ASP.NET 中)
它适用于实体框架,但我想用基本的 ADO.NET 尝试它,信息表不可用(我只是得到一个黑白屏幕,没有错误消息)
<asp:Repeater runat="server" ID="Urunler">
<ItemTemplate>
<table style="width: 500px;">
<tr>
<td><%#Eval("FirstName") %></td>
<td><%#Eval("LastName") %></td>
<td><%#Eval("Country") %></td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
这是后面的代码:
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection cnn = new SqlConnection("Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT FirstName,LastName,Country FROM Employees", cnn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Urunler.DataSource = dr.GetString(0);
Urunler.DataSource = dr.GetString(1);
}
}
cnn.Close();
//this was the EntityFW code which worked;
//Urunler.DataSource = db.Employees.Select(emp => new
//{
// emp.FirstName,
// emp.LastName,
// emp.Country
//}).ToList();
//Urunler.DataBind();
}
}
}
}