数据源不支持服务器端数据分页 [英] The data source does not support server-side data paging

查看:28
本文介绍了数据源不支持服务器端数据分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的屏幕上有一个 GridView,需要它来允许分页.

I have a GridView on my screen and need it to allow paging.

标记:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
  AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
  <Columns>
    <asp:BoundField DataField="appID" HeaderText="appID" SortExpression="appID" />
  </Columns>
</asp:GridView>

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
  SelectMethod="GetBookingId" 
  TypeName="AppointmentRepository">
  <SelectParameters>
    <asp:Parameter Name="maximumRows" Type="Int32" />
    <asp:Parameter Name="startRowIndex" Type="Int32" />
  </SelectParameters>
</asp:ObjectDataSource>

代码隐藏:

ObjectDataSource1.SelectParameters["maximumRows"].DefaultValue = "10";
ObjectDataSource1.SelectParameters["startRowIndex"].DefaultValue = "0";

LINQ 查询:

public IQueryable<tblAppointment> GetBookingId(int maximumRows, int startRowIndex)
{
    var result = (FROM a IN dc.tblAppointments
                  SELECT a).Skip(startRowIndex).Take(maximumRows);
}

但是我收到此错误:

数据源不支持服务器端数据分页.

The data source does not support server-side data paging.

我做错了什么?

推荐答案

一个简单的 ToList() 在你的结果变量上应该可以工作.

A simple ToList() on your result var should work.

编辑:正如我的回答下面的评论中所解释的,错误的原因是数据源应该实现 ICollection.IEnumerable 不会,当您执行 ToList() 时,它会将其转换为实现 ICollection 的列表.

Edit: As explained in comments below my answer, the reason for the error is that the data source should implement ICollection. IEnumerable does not, when you do ToList() it converts it into a list which implements ICollection.

这篇关于数据源不支持服务器端数据分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆