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

  • 相关阅读:
    Oracle之内存结构(SGA、PGA)
    Android添加快捷方式(Shortcut)到手机桌面
    Android悬浮窗实现 使用WindowManager
    Android闹钟 AlarmManager的使用
    JavaScript学习13 JavaScript中的继承
    Android Content Provider Guides
    Android存储访问及目录
    ReflectUitls类的编写和对反射机制的解析
    Java File类总结和FileUtils类
    JavaScript学习12 JS中定义对象的几种方式
  • 原文地址:https://www.cnblogs.com/wenming205/p/1228768.html
Copyright © 2011-2022 走看看