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

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

问题描述

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

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.

一个功能很好,用户可以设置pagesize(每页显示多少行)。

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

推荐答案

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

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);

上面的代码将为您提供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 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天全站免登陆