如何将分页应用于数据集? [英] How to apply paging to a dataset?

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

问题描述

如何将分页应用于数据集?我有一种方法可以从数据集中动态构建表.查询我从中获取数据集的数据库不是问题,但从数据集中迭代数据行很慢.

How can I apply paging to a dataset? I have a method in which I dynamically build a table from a dataset. Querying the database from which 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 want to 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).

推荐答案

如果您的数据是单个 DataTable,那么您可以使用 AsEnumerable() 扩展方法.这会将数据作为 IEnumerable 集合返回.然后,您可以使用 LINQ 扩展方法 .Skip() 和 .Take().

If your data is a single DataTable 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);

上面的代码将为您提供 MyDataTable 的第 101 到 110 行,它将是一个 IEnumerable 集合,您可以像绑定数据表一样绑定它.如果你需要它是一个实际的 DataTable,你可以这样调用 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 like 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天全站免登陆