当前位置:编程学习 > C#/ASP.NET >>

repeat 分页功能

private void DataBandtorepeat()
        {
            int curPage=System.Convert.ToInt32(this.Label2.Text);
            Response.Write(curPage);
            SqlConnection conn=db.CreateCon();
            SqlDataAdapter sda=new SqlDataAdapter();
            sda.SelectCommand=new SqlCommand("select * from stu",conn);
            DataSet ds=new DataSet();
            sda.Fill(ds,"stu");
            System.Web.UI.WebControls.PagedDataSource ps=new PagedDataSource();
            ps.DataSource=ds.Tables["stu"].DefaultView;
            ps.AllowPaging=true;
            ps.PageSize=10;
            ps.CurrentPageIndex=1;
            this.Button1.Enabled=true;
            this.Button2.Enabled=true;
            if (curPage==1)
            {
                this.Button1.Enabled=false;
            }
            if (curPage==ps.PageCount)
            {
                this.Button2.Enabled=false;
            }
            this.Repeater1.DataSource=ds.Tables["stu"];
            this.Repeater1.DataBind();
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Button2.Click += new System.EventHandler(this.Button2_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void Button1_Click(object sender, System.EventArgs e)
        {
            this.Label2.Text=System.Convert.ToString(System.Convert.ToInt32(this.Label2.Text)-1);
            this.DataBandtorepeat();

        }

        private void Button2_Click(object sender, System.EventArgs e)
        {
          this.Label2.Text=System.Convert.ToString(System.Convert.ToInt32(this.Label2.Text)+1);
          this.DataBandtorepeat();
        }
    } --------------------编程问答-------------------- 性能一般 --------------------编程问答-------------------- 路过 接分 --------------------编程问答-------------------- 路过 接分 --------------------编程问答-------------------- WTS分页三剑侠
http://community.csdn.net/Expert/topic/5290/5290374.xml?temp=.4305994 --------------------编程问答-------------------- 还不错,写得并不复杂 --------------------编程问答-------------------- 还行吧
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,