2011-05-17 82 views
-1

Possible Duplicate:
Unable to bind LINQ to gridview无法绑定LINQ

我只是用具有组简单的LINQ查询by子句,并试图将其结果设置为GridView控件绑定到GridView控件。我的LINQ查询看起来像ASP.NET页面

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

但得到的错误上

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

网格视图:

A field or property with the name 'Key' was not found on the selected data source.

任何人都可以帮我吗?

+0

种类,他至少删除了查询中的引号! – Jimmy 2011-05-17 14:31:30

+0

http://meta.stackexchange.com/questions/16721/how-does-accept-rate-work – 2011-05-17 15:14:58

回答

1

错误消息是相当明确的,要么得到从你的GridView的代码摆脱DataKeyField,或者您需要查询反对的东西,有一个名为Key

否认上述列,看来我没有注意到你的小组声明。但我仍然会尝试绑定到没有数据键字段的gridview,以确保您的查询正常运行。

+0

查询的结果是一个'IEnumerable >'。 ['IGrouping '](http://msdn.microsoft.com/zh-cn/library/bb344977.aspx)**具有**属性'Key'。 – 2011-05-17 14:28:05

+0

好点,没有注意到团体的声明 – Jimmy 2011-05-17 14:28:50