PagedDataSource objPds = new PagedDataSource();  
            DataSet ds = ucObj.DLPageBind();  
            objPds.DataSource = ds.Tables[0].DefaultView;  
            objPds.AllowPaging = true;  
            objPds.PageSize = 90;  
            int CurPage;              //当前页面从Page查询参数获取   
            if (Request.QueryString["Page"] != null)  
                CurPage = Convert.ToInt32(Request.QueryString["Page"]);  
            else  
                CurPage = 1;              objPds.CurrentPageIndex = CurPage - 1;  
            lblCurrentPage.Text = "Page: " + CurPage.ToString();              if (!objPds.IsFirstPage)  
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);              if (!objPds.IsLastPage)  
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);              ////把PagedDataSource 对象赋给Repeater控件   
            this.DLClass.DataSource = objPds;  
            this.DLClass.DataBind();   这是我从网上找的对datalist的分页,我大体改了改放在用户控件中,但运行之后只有首页没事,在其它页就好像有冲突了  点下一页 页面的其它内容就没了,只有对datalist控件绑定的内容。为什么会这样啊?  这句话啥意思啊:  
Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);  

解决方案 »

  1.   

    URL分页,得到currentindexpage值的应该是.
      

  2.   

    网上有很多datalist分页的例子,曾经找到4,5个方法呢
      

  3.   

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["pageindex"] = "0";
                BindData(); 
            }
        }
        private void BindData()
        {
            DataTable objTable = new DataTable();
            string connectionstring = ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString;
            using (SqlConnection sc = new SqlConnection(connectionstring))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter("", sc))
                {
                    sda.Fill(objTable);
                }
            }
            if (objTable != null && objTable.Rows.Count > 0)
            {
                DataView objView = objTable.DefaultView;
                PagedDataSource objPds = new PagedDataSource();
                objPds.DataSource = objView;            objPds.AllowPaging = true;
                objPds.PageSize = 10;
                objPds.CurrentPageIndex = int.Parse(ViewState["pageindex"].ToString());            if (!objPds.IsFirstPage)
                    lkPre.Visible = true;
                else
                    lkPre.Visible = false;
                if (!objPds.IsLastPage)
                    lkNext.Visible = true;
                else
                    lkNext.Visible = false;
                dlData.DataSource = objPds;
                dlData.DataBind();
            }
        }
        protected void IndexChanging(object sender, EventArgs e)
        {
            string strCommand = ((LinkButton)sender).CommandArgument.ToString();
            int pageindex = int.Parse(ViewState["pageindex"].ToString());
            if (strCommand == "pre")
                pageindex = pageindex - 1;
            else
                pageindex = pageindex + 1;
            ViewState["pageindex"] = pageindex;
            BindData();
        }
      

  4.   

        private void BindNewsData()
        {
            //datatable实现从数据库获取数据
            DataTable dt = new DataTable();
            string connectionstring = ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString;
            using (SqlConnection sc = new SqlConnection(connectionstring))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter("", sc))
                {
                    sda.Fill(dt);
                }
            }
            ///设定控件的数据源
            //DataList3.DataSource = dt;
            ///绑定控件的数据
            //DataList3.DataBind();
            PagedDataSource objPds = new PagedDataSource();
            objPds.DataSource = dt.DefaultView;
            objPds.AllowPaging = true;
            objPds.PageSize = 10;
            int curPage;
            if(Request.QueryString["Page"]!=null)
                curPage = Convert.ToInt32(Request.QueryString["Page"]);
            else
                curPage = 1;
            objPds.CurrentPageIndex = curPage - 1;
            lblCurrentPage.Text = "Page: " + curPage.ToString();
            if (!objPds.IsFirstPage)
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage - 1);
            if (!objPds.IsLastPage)
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage + 1);
            DataList3.DataSource = objPds;
            DataList3.DataBind();
        }