我的屏幕上有一个GridView,需要它来允许分页。
标记:
<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);
}
然而,我收到了这个错误:
数据源不支持服务器端数据分页。
我做错了什么?
发布于 2009-11-02 21:26:53
结果变量上的一个简单的ToList()
应该可以工作。
编辑:正如我的答案下面的注释中所解释的那样,错误的原因是数据源应该实现ICollection。IEnumerable不会,当您执行ToList()
时,它会将其转换为实现ICollection的列表。
发布于 2010-05-14 18:48:23
你也可以使用泛型List<T>
。请参阅示例代码片段:
public List<Company> GetContactList(int startindex)
{
string path = Server.MapPath("~/contacts.xml");
XDocument xd = XDocument.Load(path);
IEnumerable<Company> results = (from items in xd.Elements("Company").Elements("Contact")
select new Company
{
Id = items.Element("ID").Value,
Photo = (string)items.Element("photo").Value,
Name = (string)items.Element("Name").Value,
BloodGroup = (string)items.Element("Bg").Value,
Dob = (string)items.Element("dob").Value,
Anniversery = (string)items.Element("avd").Value,
Mobile = (string)items.Element("cnum").Value,
designation = (string)items.Element("desig").Value,
Team = (string)items.Element("team").Value
}).Skip(startindex*10).Take(10);
return (List<Company>) results;
}
您还可以使用DataSet/DataTable代替DataReader。
发布于 2013-12-14 01:42:11
.ToList()
在DataSource的末尾,我分配的工作如下所示:
gvCaseLabelsLeft.DataSource = caseLabelsList.OrderBy(c=>c.caseLabelNumber).ToList();
https://stackoverflow.com/questions/1661292
复制相似问题