ListView的高效分页

mac2022-06-30  18

需要在DataSet中设定两个sql查询

1.根据参数查询指定页的数据GetDataByPage

select *from ( select id,name,age,over(order by id)rownum from table where id>30 )t where t.rownum>@startRowIndex and t.rownnm<=@startRowIndex+@maximumRows

这里注意!因为DataSet编辑器对over()函数不支持,所以要手动添加parameter设定参数,注意添加parameter时参数不用带@

@startRowIndex,@maximumRows这两个参数名是指定的,一般不变。

 

2.查询数据库中的总数据个数QueryCount

select count(*)from table

然后先按照正常流程添加ObjectDataSource(这里必须选择getData()函数,不然ListView找无法配置数据源),ListView(编辑,插入,删除,分页)

配置好后回到aspx代码页面

重新配置ObjectDataSource的获得数据方法,然后会自动生成两个传参,删掉即可!不删会报错!

将ObjectDataSource的SelectMethod设置为取得分页数据的方法,SelectCountMethod设置为取得行数的方法,EnablePaging设为true

网址的可传递性(分享):设置DataPager的QueryStringField="paganum"

让分页后的导航显示页数在中间的方法

在页数标签前后放置各一个翻页标签,然后前面的翻页标签隐藏“下一页”,“尾页”,后面的翻页标签隐藏“前一页”,“首页”。

 aspx页ObjectDataSource控件主要代码:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetDataByPage" SelectCountMethod="QueryCount" EnablePaging="True"> </asp:ObjectDataSource>

  

 

 aspx页DataPager控件代码:

<asp:DataPager ID="DataPager1" runat="server" PageSize="3"> <Fields> <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowPreviousPageButton="true" ShowNextPageButton="false" /> <asp:NumericPagerField ButtonType="Link" ButtonCount="3" /> <asp:NextPreviousPagerField ButtonType="Button" ShowNextPageButton="true" ShowLastPageButton="true" ShowPreviousPageButton="false" /> </Fields> </asp:DataPager>

  

转载于:https://www.cnblogs.com/blackHorseplan/p/3893374.html

相关资源:如何实现ListView高效分页代码
最新回复(0)