欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-03-02 12:13:34
复制代码 代码如下: pageddatasource objpage = new pageddatasource();    &n...

复制代码 代码如下:

 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() + "/" + 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();