asp.net中使用repeater和PageDataSource搭配实现分页代码


 PagedDataSource objPage = new PagedDataSource();

DataView dv = bllBook.GetListByState("", true);
            //设置数据源
            objPage.DataSource =dv ;

//允许分页
            objPage.AllowPaging = true;

//设置每页显示的项数
            objPage.PageSize = 10;


            //定义变量用来保存当前页索引
            int CurPage;
            int RecordCount;
            int PageCount = objPage.PageCount;

RecordCount = dv.Count;

//判断是否具有页面跳转的请求
            if (Request.QueryString["Page"] != null)
            {
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);
            }

else
            {
                CurPage = 1;
            }

//设置当前页的索引
            objPage.CurrentPageIndex = CurPage - 1;

//显示状态信息
            lblCurPage.Text = "第  " + CurPage.ToString() + "https://www.jb51.net/" + PageCount.ToString() + "页    共  " + RecordCount.ToString() + " 记录 ";

//如果当前页面不是首页
            if (!objPage.IsFirstPage)
            //定义 "上一页 "超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
            {
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
                lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(1);
            }

//如果当前页面不是最后一页
            if (!objPage.IsLastPage)
            //定义 "下一页 "超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
            {
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
                lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageCount);
            }

//进行数据绑定
            Repeater1.DataSource = objPage;
            Repeater1.DataBind();

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgssj.html