写出代码之前,先说明一下原理,比较简单。有一张表(test)如下 
结构是:id(自动编号) txt   假设40条记录)
现在要每页显示10条记录,则每页要显示的数据应该是:
第一页:1----10
第二页:11----20
第三页:21----30
第四页:31----40

如要显示第一页,最简单的方法就是 select top 10 * from test 就OK了。

第二页开始呢?怎么做呢?请接着看:
比如我要显示第三页:也就是21----30
原理:找出不要的数据也就是1----20,最大的id,这是里20
再找出大于这个id(20) 前10条记录就OK了。

原理知道后写代码就简单了,前台界面比较简单,不多说,代码如下

百万条数据分页<asp:LinkButton id="lbtnFirst" Runat="server">首頁</asp:LinkButton>
百万条数据分页
<asp:LinkButton id="lbtnBack" Runat="server">上頁</asp:LinkButton>
百万条数据分页
<asp:LinkButton id="lbtnNext" Runat="server">下頁</asp:LinkButton>
百万条数据分页
<asp:LinkButton id="lbtnLast" Runat="server">尾頁</asp:LinkButton>
百万条数据分页
<asp:Label id="Label1" runat="server">当前页:</asp:Label>
百万条数据分页
<asp:Label id="lblCurrentPage" runat="server">1</asp:Label>
百万条数据分页
<asp:Label id="Label2" runat="server">总页:</asp:Label>
百万条数据分页
<asp:Label id="lblPageCount" runat="server">200</asp:Label>
百万条数据分页
<asp:Label id="Label3" runat="server">跳转:</asp:Label>
百万条数据分页
<asp:TextBox id="txtToPage" runat="server" Width="88px"></asp:TextBox>
百万条数据分页
<asp:Button id="btnToPage" runat="server" Text="go"></asp:Button>
百万条数据分页
<asp:DataGrid id="DataGrid1" runat="server" AllowPaging="True" AllowCustomPaging="True"></asp:DataGrid>

后台代码:

 

百万条数据分页private void Page_Load(object sender, System.EventArgs e)

 

亲自测试sql2000 460万条记录,显示速度很快

相关文章: