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();

 

        }

你可能感兴趣的:(c,ListView,dataset)