Datalist Repeater分页

不同与GridView ListView支持分页(Gridview ListView还允许用户编辑、删除数据以及排序,ListView还支持插入数据),DataList和Repeater不支持分页,要想分页需要编码,可参考下面的代码

public void dlBind()          //数据绑定  分页

        {

 

            int curpage = Convert.ToInt32(this.LabCurPageNumber.Text);

            PagedDataSource ps = new PagedDataSource();

 

            DataSet myds = new DataSet();

            myds.ReadXml(@"C:/Documents and Settings/Administrator/桌面/资源检索系统/Data/result.xml");

            ps.DataSource = myds.Tables[0].DefaultView;

 

            ps.AllowPaging = true;

            ps.PageSize = 3;

            ps.CurrentPageIndex = curpage - 1;   //获得当前页的索引

 

            if (ps.DataSourceCount <= ps.PageSize)

            {

                this.LBFirst.Visible = false;

                this.LBLast.Visible = false;

                this.LBNext.Visible = false;

                this.LBUp.Visible = false;

                this.LabCurPageNumber.Visible = false;

                this.LabTotalPageNumber.Visible = false;

                this.LBTotalPage.Visible = false;

                this.LBCurrentpage.Visible = false;

            }

            else

            {

 

                this.LBFirst.Visible = true;

                this.LBLast.Visible = true;

                this.LBNext.Visible = true;

                this.LBUp.Visible = true;

                this.LabCurPageNumber.Visible = true;

                this.LabTotalPageNumber.Visible = true;

                this.LBTotalPage.Visible = true;

                this.LBCurrentpage.Visible = true;

 

 

                if (curpage == 1)

                {

                    this.LBFirst.Visible = false;

                    this.LBUp.Visible = false;

                }

                if (curpage == ps.PageCount)

                {

                    this.LBLast.Visible = false;

                    this.LBNext.Visible = false;

                }

                this.LabTotalPageNumber.Text = Convert.ToString(ps.PageCount);

 

            }

            DataList1.DataSource = ps;

            DataList1.DataBind();

 

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值