zoukankan      html  css  js  c++  java
  • datalist分页 :PagedDataSource为datalist分页

    PagedDataSource pds = new PagedDataSource();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                gvBind();
            }
        }
        private void gvBind()
        {
            //获取数据源
            SqlConnection con = new SqlConnection("server=.;database=pubs;uid=sa;pwd=sa");
            SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            //赋值数据源
            pds.DataSource = ds.Tables[0].DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = 4;
            int curPage;
            if (Request.QueryString["pg"] != null)
            {
                curPage = Int32.Parse(Request.QueryString["pg"]);//??要判断一下是否为整数
            }
            else
                curPage = 1;
            pds.CurrentPageIndex = curPage - 1;
            this.lbPageNum.Text = curPage.ToString();
            this.lbTotalPage.Text = pds.PageCount.ToString();
            //如果当前页不为首页,则设置“前一页”的URL
            if (!pds.IsFirstPage)
            {
                LinkPre.NavigateUrl = Request.CurrentExecutionFilePath + "?pg=" + Convert.ToString(curPage - 1);

            }
            if (!pds.IsLastPage)
            {
                LinkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?pg=" + Convert.ToString(curPage + 1);

            }
            //设置首页
            LinkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?pg=1";
            LinkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?pg=" + pds.PageCount.ToString();
            DataList1.DataSource = pds;
            DataList1.DataBind();
        }

  • 相关阅读:
    Java8 Stream
    一个轻量级的基于RateLimiter的分布式限流实现
    常用限流算法与Guava RateLimiter源码解析
    Java学习之socket网络编程篇
    Java学习之文件io流篇
    Java学习之异常篇
    Java学习之多线程篇
    Java学习之集合篇
    Java学习之常用类篇
    Java学习之final与匿名内部类篇
  • 原文地址:https://www.cnblogs.com/wenming205/p/1228768.html
Copyright © 2011-2022 走看看