protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack) 
        {
            this.Label2.Text = "1";
            this.databind();
        }
    }    private void databind()
    {
        int nowpage = Convert.ToInt32(this.Label2.Text);
        string myconnection = "server=wang\\SQLEXPRESS;database=wang;uid=sa;pwd=123456";
        SqlConnection conn = new SqlConnection(myconnection);
        conn.Open();
        string mysql = "SELECT * FROM userimages  order by id desc";
        SqlDataAdapter mybook = new SqlDataAdapter(mysql, conn);
        DataSet ds = new DataSet();
        mybook.Fill(ds, "userimages");
        PagedDataSource ps = new PagedDataSource();
        ps.DataSource = ds.Tables["userimages"].DefaultView;
        ps.AllowPaging = true;
        ps.PageSize = 2;
        ps.CurrentPageIndex = nowpage-1;
        this.Button1.Enabled = true;
        this.Button2.Enabled = true;
        this.Button3.Enabled = true;
        this.Button4.Enabled = true;
        this.DataList1.DataSource = ps;
        this.DataList1.DataBind();    }
为什么ps.CurrentPageIndex = nowpage-1;这里要-1,我的nowpage本来就是1,再-1不就是0了吗?
还有,最后一页又是怎么表示呢?

解决方案 »

  1.   

    aspnetpager 分页控件
    this.DataList1.DataSource =ps ;DataSet ds=new DataSet();   
    PagedDataSource objPage=new PagedDataSource();   
    objPage.DataSource=ds.Tables["user"].DefaultView;   
    objPage.AllowPaging=true;   
    objPage.PageSize=6;   
    int CurPage;   
    if(Request.QueryString["Page"]!=null)   
    CurPage=Convert.ToInt32(Request.QueryString["Page"]);   
    else   
    CurPage=1;   
    objPage.CurrentPageIndex=CurPage-1;   
    this.lblCurPage.Text="当前页:第"+CurPage.ToString()+"页";   
    this.DataList1.DataSource=objPage;   
    this.DataList1.DataBind();   
    asp.netpager结合PagedDataSource
    DataPager+ObjectDataSource
    http://topic.csdn.net/u/20100815/20/6aba9d03-41fb-4a01-87df-5eae17c80a75.html
      

  2.   

    最后一页
    ds.Tables["userimages"].DataRow.count()/pagesize -1