【问题标题】:Unable to bind LINQ to gridview [duplicate]无法将 LINQ 绑定到 gridview [重复]
【发布时间】:2011-05-17 14:24:18
【问题描述】:

可能重复:
Unable to bind LINQ to gridview

我只是使用具有 group by 子句的简单 LINQ 查询并尝试将其结果集绑定到 GridView。我的 LINQ 查询看起来像

var expData = from c in WebDB.TblTrans
              group c by c.transdate into g
              select g;

ASP.NET 页面上的网格视图

<asp:GridView ID="GridView1" AutoGenerateColumns="true" runat="server" DataKeyField="Key" />

但得到错误:

在所选数据源中找不到名为“Key”的字段或属性。

谁能帮帮我?

【问题讨论】:

标签: c# linq


【解决方案1】:

错误消息非常明确,要么从您的 gridview 代码中删除 DataKeyField,要么您需要查询具有名为 Key 的列的内容

无视上述,我似乎没有注意到你的团体声明。但我仍然会尝试在没有数据键字段的情况下绑定到 gridview 以确保您的查询正常运行

【讨论】:

猜你喜欢
  • 2011-08-27
  • 1970-01-01
  • 2013-03-15
  • 1970-01-01
  • 2014-01-13
  • 2012-04-20
  • 1970-01-01
  • 1970-01-01
  • 2019-09-02
相关资源
最近更新 更多