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

  • 相关阅读:
    微服务-分布式事务解决方案
    Python cannot import name 'Line' from 'pyecharts'
    powershell 基础
    Linux SSH config
    神奇的Python代码
    GitHub 中 readme 如何添加图片
    Linux 笔记(自用)
    Anaconda 安装 TensorFlow ImportError:DLL加载失败,错误代码为-1073741795
    Ubuntu 分辨率更改 xrandr Failed to get size of gamma for output default
    Git入门教程 Git教程入门
  • 原文地址:https://www.cnblogs.com/wenming205/p/1228768.html
Copyright © 2011-2022 走看看