linq group not working in gridview

Posted by Dipu710646 under Regular Expressions on 1/13/2011 | Points: 10 | Views : 2195 | Status : [Member] | Replies : 2
Hello All,

I have a table called ResourceMaster containing EmployeeID as primary key, ReportingMgr along with many other column.

I want to fetch the records group by the reporting manager.

Here is my query :

var MyUsers = from users in DC.GetTable<ResourceMaster>()
group users by users.ReportingMgr into MyGroup
orderby MyGroup.Key
select MyGroup;
Gridview1.DataSource = MyUsers;
Gridview1.DataBind();

But I am getting an error " A field or property named 'Key' is not found"..

Any reply is appreciated.

Cheers,
Dipankar




Responses

Posted by: Swapnil on: 1/21/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Dipankar,

Try using,
var MyUsers = from users in DC.GetTable<ResourceMaster>()
group users by users.ReportingMgr into MyGroup
orderby users.Key
select MyGroup;

Thanks,
Swapnil

Thanks and Regards,
Swapnil

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/22/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Orderby key can be taken from the group taken not the alias so use the code as swapnil given above.

Thanks
Karthik
www.f5Debug.net

Dipu710646, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response