您的位置:首页 > 编程语言 > ASP

ASP.NET自定义简单分页

2012-02-27 14:27 302 查看
首先有个数据库

表名为student

字段为sno、sname、sage

public static class Paging
{
static Paging() { }

public static int PageBindRepeater(int curPage,int pageSize, Repeater rep,string strSql)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = DbHelperSQL.GetTable(strSql).DefaultView;
pds.AllowPaging = true;
pds.PageSize = pageSize;
pds.CurrentPageIndex = curPage - 1;
rep.DataSource = pds;
rep.DataBind();
return pds.PageCount;
}
}


分页类,此类会将指定的Repeater控件上绑定 指定的某一页的数据

第一个参数是当前页数(也就是要显示的哪页);

第二个参数是分页的大小,为多少数据为一页;

第三个参数是Repeater的id;

第四个参数是sql语句,将所有数据一次性加载。

返回值是一共有多少页。

string PageCount = Paging.PageBindRepeater(1, 6, Repeater1, "select * from student").ToString();


后台使用

显示第1页数据

每6条数据为一页;

绑定Repeater1;

数据为所有学生。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: