如何申请分页数据集? [英] How to apply paging to a dataset?

查看:157
本文介绍了如何申请分页数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何申请分页数据集?我在我至极动态地从数据集中建一个表的方法。查询从至极的数据库我得到我的数据集从不是问题,但是从数据集进行迭代的数据行是缓慢的。

How can i apply paging to a dataset? I have a method in wich i dynamically build a table from a dataset. Querying the database from wich i get my dataset from is not an issue but iterating the datarows from the dataset is slow.

要装载包含了大量数据行的我想申请分页​​功能页面时提高性能。

To increase performance when loading a page containing a lot of datarows i wanna apply paging ability.

有一个特点,这将是件好事,是为用户设置页面大小(多少行显示每一页)。

A feature that would be good to have is ability for the user to set pagesize (how many rows to display on each page).

推荐答案

如果你的数据是单一个确定时代,那么你可以使用AsEnumerable()扩展方法。这将返回的数据作为IEnumerable集合。然后,您可以使用LINQ扩展方法.Skip()和。取()。

If your data is single a single datable then you can use the AsEnumerable() extension method. That will return the data as an IEnumerable collection. You can then use the LINQ extension methods .Skip() and .Take().

IEnumerable<DataRow> MyDataPage = MyDataTable.AsEnumerable().Skip(100).Take(10);

以上code会给你行101 MyDataTable 110,这将是一个IEnumerable集合,你可以绑定只是liek的数据表。如果你需要它是一个实际的数据表,你可以叫CopyToDataTable()这样的:

The above code would give you rows 101 to 110 of MyDataTable and it would be an IEnumerable collection which you can bind just liek a data table. If you need it to be an actual DataTable you can just call CopyToDataTable() thus:

DataTable NewDT = MyDataPage.CopyToDataTable();

更详细的信息,请这里

这篇关于如何申请分页数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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