无法将 LINQ 绑定到 gridview
我只是使用一个带有 group by 子句的简单 LINQ 查询,并尝试将其结果集绑定到 GridView。 我的 LINQ 查询看起来像
var expData = from c in WebDB.TransTable
group c by c.enterdate into g
select g;
ASP.NET 页面上的网格视图,
<asp:GridView ID="GridView1" AutoGenerateColumns="true" runat="server" DataKeyField="Key" />
但出现错误:
在所选数据源中找不到名为“Key”的字段或属性。
有人可以帮我吗?
所有答案都没有帮助
I just using a simple LINQ query having group by clause and trying to bind its result set to GridView.
My LINQ query looks like
var expData = from c in WebDB.TransTable
group c by c.enterdate into g
select g;
Grid view on ASP.NET page
<asp:GridView ID="GridView1" AutoGenerateColumns="true" runat="server" DataKeyField="Key" />
But getting the error:
A field or property with the name 'Key' was not found on the selected data source.
Anyone can help me please?
None of the answers were helpful
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
expData
是一个string
,因为您已将 LINQ 查询放在引号内。System.String
没有名为Key
的属性,因此出现错误。如果删除引号,它应该一切正常。
expData
is astring
as you've put the LINQ query inside quotation marks.System.String
does not have a property calledKey
, hence the error.If you remove the quotation marks it should all work fine.
编辑这会忽略 linq 语句中的“”
查看 asp.net GridView 上的属性(aspx 代码):DataKeyField="" 指向 linq 查询中不存在的列名
EDIT This ignores the "" in your linq statement
Look at the attribute on your asp.net GridView(aspx code): DataKeyField="" is pointing to a column name that does not exist in your linq query
我也有你的问题,我是这样写的。我希望这对你有用:
I had your problem either , I wrote like this . I hope this work for you :