首先要先引用AspNetPager.dll文件

然后在<html>上面添加下面代码:

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

然后在repeater控件下添加AspNetPager控件:

<webdiyer:aspnetpager id="AspNetPager1"
           runat="server"
           PageSize="100"
           AlwaysShow="True"
           OnPageChanged="AspNetPager1_PageChanged"
           ShowCustomInfoSection="left"
           CustomInfoSectionWidth=""
           ShowPageIndexBox="Always"
           PageIndexBoxType="DropDownList"
           CustomInfoHTML="共<font color='red'><b>%RecordCount%</b></font>条记录" FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PrevPageText="上一页">
</webdiyer:aspnetpager>

接着在后台代码中分页:

AspNetPager1.CurrentPageIndex = 1;//设置或获取当前页
 PagedDataSource pds = new PagedDataSource();//新建数据集
 pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;设置索引(索引从0开始)
 pds.DataSource = new List<SalesCarModel>();//清空数据源
 pds.AllowPaging = true;//是否启用分页
 pds.PageSize = AspNetPager1.PageSize;//获取或设置每页的项数
 ucSalesCar.DataBindSource(pds) ;//绑定到数据控件
 BindDatasource();//一个方法:主要是查询的条件和查询的结果和对分页控件的属性设置

private void AspNetPager1_PageChanged(object sender, EventArgs e)

{

  BindDatasource();更新页数

}

这样就完成了

---做笔记

05-08 08:08