asp.net高效分页的办法

来源:互联网 发布:java log4j 配置文件 编辑:程序博客网 时间:2024/05/22 03:14
分页控件:DataPager控件
1、微软封装的控件中,只有listview控件能使用DataPager控件。
2、只有实现了IPageableItemContauner接口的控件才能使用DataPager控件。
3、Datapager控件的显示风格是在Fields中的字段设置,可以组合使用数字页号和上下页风格等,也可混合使用。


  使用ListView 高效率分页:
1、给结果集编号
select id, Username,Comment, row_number() over(order by ID)rownum from T_UserComment


2、取第多少条数据到第多少条数据做为一页,进行分页。
select * from (select id, Username,Comment, row_number() over(order by ID)rownum from T_UserComment)t where t.rownum <=10 and t.rownum>=1


3、配置数据集,添加两个方法:查询数据条数Select count(*) from T_UserComment、查询分页的数据(从多少条数据到多少条数据进行分页) 
select * from (select id, Username,Comment, row_number() over(order by ID)rownum from T_UserComment)t where t.rownum >@startRowIndex and t.rownum>=@startRowIndex+@maximumRows
 生成数据集,


4、(注意:先按常规配置,然后配置Listview以后再详细配置ObjectDataSource否则Listview会出现异常)配置ObjectDataSource,添加SelectCountMethod(查询数量)属性,SelectMothod(每页的数据),启用EnablePaging属性.


5、配置listview,OK。


实例见:E:\newd\我的文档\Visual Studio 2010\WebSites\数据控件\ListView高效分页
原创粉丝点击