Unable to bind LINQ to gridview

前端 未结 3 1667
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 00:43

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.Tra         


        
相关标签:
3条回答
  • 2021-01-28 01:20

    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

    <asp:GridView AutoGenerateColumns="true" DataKeyField="Key"/>
    
    0 讨论(0)
  • 2021-01-28 01:23

    I had your problem either , I wrote like this . I hope this work for you :

    var expData = from c in WebDB.TransTable
                  group c by c.enterdate into g
                  select new {EnterDate = g.Key};
    
    0 讨论(0)
  • 2021-01-28 01:25

    expData is a string as you've put the LINQ query inside quotation marks.

    var expData = "from c in WebDB.TransTable
                group c by c.enterdate into g
                  select g;"
    

    System.String does not have a property called Key, hence the error.

    If you remove the quotation marks it should all work fine.

    0 讨论(0)
提交回复
热议问题