【发布时间】:2013-12-17 09:53:58
【问题描述】:
我正在尝试使用 LINQ 查询将 DataTable 中的数据显示到 GridView 中,但我无法理解为什么此代码不起作用。实际上 GridView 显示 RowError HasError 消息。我完全糊涂了。
这是我的代码
protected void Page_Load(object sender, EventArgs e)
{
DataTable table = (DataTable)Session["userTable"];
string compare = Request.QueryString["id"].ToString();
var data = from x in table.AsEnumerable()
where x.Field<string>("Userid") == compare
select x;
GridView1.DataSource = data;
GridView1.DataBind();
}
【问题讨论】:
-
您能否更具体地了解错误的含义?
-
不需要
var dtNew = data .CopyToDataTable(); GridView1.DataSource = dtNew ; GridView1.DataBind();?? -
实际上没有编译或运行时错误,但在gridview中没有显示任何内容
-
非常非常感谢!它有效!