In my case this error was a little misleading:
The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
to fix replace the following
<asp:GridView ID="GridView1" runat="server" ItemType="WebApplication9.Dpt" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" PageSize="1" SelectMethod="GetDepartments">
<Columns>
<asp:BoundField DataField="DepartmentId" HeaderText="Department Id" SortExpression="DepartmentId" />
<asp:BoundField DataField="DepartmentName" HeaderText="Department Name" SortExpression="DepartmentName" />
<asp:TemplateField HeaderText="# of users in department">
<ItemTemplate><%#: Item.Users.Count() %></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
with
<asp:GridView ID="GridView1" runat="server" ItemType="WebApplication9.Dpt" AutoGenerateColumns="False" DataKeyNames="DepartmentId"
AllowPaging="True" AllowSorting="True" PageSize="1" SelectMethod="GetDepartments">
<Columns>
<asp:BoundField DataField="DepartmentId" HeaderText="Department Id" SortExpression="DepartmentId" />
<asp:BoundField DataField="DepartmentName" HeaderText="Department Name" SortExpression="DepartmentName" />
<asp:TemplateField HeaderText="# of users in department">
<ItemTemplate><%#: Item.Users.Count() %></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I had gridview
<asp:GridView ID="GridView1" runat="server" ItemType="WebApplication9.Dpt" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" PageSize="1" SelectMethod="GetDepartments">
<Columns>
<asp:BoundField DataField="DepartmentId" HeaderText="Department Id" SortExpression="DepartmentId" />
<asp:BoundField DataField="DepartmentName" HeaderText="Department Name" SortExpression="DepartmentName" />
<asp:TemplateField HeaderText="# of users in department">
<ItemTemplate><%#: Item.Users.Count() %></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
with selectMethod
public IQueryable<Dpt> GetDepartments()
{
var query = this.db.Dpts
.Include(c => c.Users);
return query;
}
and forgot data key names.....
No comments:
Post a Comment