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

  • 相关阅读:
    基于element-ui图片封装组件
    计算时间间隔具体每一天
    C语言学习笔记 —— 函数作为参数
    AtCoder Beginner Contest 049 题解
    AtCoder Beginner Contest 048 题解
    AtCoder Beginner Contest 047 题解
    AtCoder Beginner Contest 046 题解
    AtCoder Beginner Contest 045 题解
    AtCoder Beginner Contest 044 题解
    AtCoder Beginner Contest 043 题解
  • 原文地址:https://www.cnblogs.com/wenming205/p/1228768.html
Copyright © 2020-2023  润新知