无法绑定的LINQ to GridView控件 [英] Unable to bind LINQ to gridview
问题描述
我只是用一个简单的性基团的LINQ查询by子句,并试图它的结果设置为GridView控件绑定。
我的LINQ查询看起来像
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;
ASP.NET页面上的网格视图
Grid view on ASP.NET page
<asp:GridView ID="GridView1" AutoGenerateColumns="true" runat="server" DataKeyField="Key" />
但得到的错误:
名为'关键'字段或属性没有被选中的数据源上找到。
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
推荐答案
修改这忽略了,你的LINQ声明
EDIT This ignores the "" in your linq statement
看你的asp.net的GridView属性(ASPX code):DataKeyField =指向并不在你的LINQ查询存在的列名
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
<asp:GridView AutoGenerateColumns="true" DataKeyField="Key"/>
这篇关于无法绑定的LINQ to GridView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!