AspNetPager控件使用方式:引用到项目>工具箱右键>选择项>浏览引用的DLL文件
此时工具箱多了一个控件,直接拖到页面上,自动生成一下代码.
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
这里的上一页和下一页都可以在图形界面下设置,非常简单使用
<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
CustomInfoHTML="共%PageCount%页,当前为第%CurrentPageIndex%页,每页%PageSize%条"
FirstPageText="首页" LastPageText="尾页" NextPageText="下一页"
PageIndexBoxType="TextBox" PrevPageText="上一页" ShowBoxThreshold="5"
ShowCustomInfoSection="Left" ShowPageIndexBox="Auto" SubmitButtonText="Go"
TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到" UrlPaging="True">
</webdiyer:AspNetPager>
后台代码:
NorthwindEntities db = new NorthwindEntities();
List<Customers> tmpList= db.Customers.ToList();
AspNetPager1.PageSize = 10;
AspNetPager1.RecordCount=tmpList.Count; //设置分页控件的总记录数
//这就是跳过的数据条数
int skipCount;
if (Request["page"] != null)
skipCount = (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize; //这里实现了gridview和分页控件之间的关联
else
skipCount = 0;
this.GridView1.DataSource = tmpList.Skip(skipCount).Take(AspNetPager1.PageSize);
this.GridView1.DataBind();
示例源码可以在 http://download.csdn.net/source/3546273 处下载
运行效果