日期:2014-05-18 浏览次数:20667 次
articles= sm.GetArticles();//articles是List<Articles>类型
pds.DataSource = articles;
this.GridView1.DataSource = pds;//pds为PagedDataSource类型的对象
pds.PageSize = 3;
pds.AllowPaging = true;
if (Request.QueryString["page"] == null)
{
currentPage = 0;
}
else
{
currentPage = int.Parse(Request.QueryString["page"]);
}
pds.CurrentPageIndex = currentPage;
if (!pds.IsFirstPage)
{
this.HyperLink1.NavigateUrl = "GridView.aspx?page=" + (currentPage - 1).ToString();
}
if (!pds.IsLastPage)
{
this.HyperLink2.NavigateUrl = "GridView.aspx?page=" + (currentPage + 1).ToString();
}
------解决方案--------------------
如果采用GridView进行分页
首先先将 AllowPaging属性设置为true
然后将PageSize设置为10
最后在分页事件(PageIndexChanging)中写入:GridView.PageIndex = e.NewPageIndex.
即可。
前提是DataSource必须是已经绑定到GridView中
使用DataList获这Repeater分页
可以使用PagedDataSource去绑定一个数据集
PagedDataSource pd = new PagedDataSource();
pd.PageSize = 10;
pd.AllowPaging = true;
pd.CurrentPageIndex = 0;
pd.DataSource = (List<>数据集);
最后设置DataList或者repeater的DataSource=pd;
换页的时候只要改变CurrentPageIndex的值后重新绑定数据就可以
pd.Count可以获得总的分页数