故障描述  下一页的时候 点第一下 行 点第二下,却还在第二页 即使还有第三页。这是前台页:(.aspx)  int PageSize, RecordCount, PageCount, CurrentPage;
    protected void Page_Load(object sender, EventArgs e)
    {        PageSize = 20;
        ListBind();
        CurrentPage = 0;        ViewState["PageIndex"] = 0;
        //计算总共有多少记录 
        RecordCount = CalculateRecord();
        lblRecordCount.Text = RecordCount.ToString();        //计算总共有多少页 
        PageCount = RecordCount / PageSize + 1;
        lblPageCount.Text = PageCount.ToString();
        ViewState["PageCount"] = PageCount;
    }
   
    //计算总共有多少条记录 
    public int CalculateRecord()
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
                                               
        conn.Open();
        int intCount;
        string strCount = "select count(*) from article where classid=1 ";
        SqlCommand MyComm = new SqlCommand(strCount, conn);
        intCount = Convert.ToInt32(MyComm.ExecuteScalar());
        return intCount;
    }    ICollection CreateSource()
    {        int StartIndex;
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
        conn.Open();        //设定导入的起终地址 
        StartIndex = CurrentPage * PageSize;
        string strSel = "select * from article where classid=1 order by articleid desc";
        DataSet ds = new DataSet();        SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, conn);
        MyAdapter.Fill(ds, StartIndex, PageSize, "article");        return ds.Tables["article"].DefaultView; 
    }
    public void ListBind()
    {
        this.newsmore.DataSource = CreateSource();
        this.newsmore.DataBind();        lbnNextPage.Enabled = false;
        lbnPrevPage.Enabled = true;
        if (CurrentPage == (PageCount - 1)) lbnNextPage.Enabled = false;
        if (CurrentPage == 0) lbnPrevPage.Enabled = false;
        lblCurrentPage.Text = (CurrentPage + 1).ToString();
    }
    public void Page_onClick(Object sender, CommandEventArgs e)
    {
        CurrentPage = (int)ViewState["PageIndex"];
        PageCount = (int)ViewState["PageCount"];        string cmd = e.CommandName;
        //判断cmd,以判定翻页方向 
        switch (cmd)
        {
            case "next":
                if (CurrentPage < (PageCount - 1)) CurrentPage++;
                break;
            case "prev":
                if (CurrentPage > 0) CurrentPage--;
                break;
        }        ViewState["PageIndex"] = CurrentPage;
        ListBind();
    }这是后台程序页(.cs)    int PageSize, RecordCount, PageCount, CurrentPage;
    protected void Page_Load(object sender, EventArgs e)
    {        PageSize = 20;
        ListBind();
        CurrentPage = 0;        ViewState["PageIndex"] = 0;
        //计算总共有多少记录 
        RecordCount = CalculateRecord();
        lblRecordCount.Text = RecordCount.ToString();        //计算总共有多少页 
        PageCount = RecordCount / PageSize + 1;
        lblPageCount.Text = PageCount.ToString();
        ViewState["PageCount"] = PageCount;
    }
   
    //计算总共有多少条记录 
    public int CalculateRecord()
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
                                               
        conn.Open();
        int intCount;
        string strCount = "select count(*) from article where classid=1 ";
        SqlCommand MyComm = new SqlCommand(strCount, conn);
        intCount = Convert.ToInt32(MyComm.ExecuteScalar());
        return intCount;
    }    ICollection CreateSource()
    {        int StartIndex;
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["data"].ToString());
        conn.Open();        //设定导入的起终地址 
        StartIndex = CurrentPage * PageSize;
        string strSel = "select * from article where classid=1 order by articleid desc";
        DataSet ds = new DataSet();        SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel, conn);
        MyAdapter.Fill(ds, StartIndex, PageSize, "article");        return ds.Tables["article"].DefaultView; 
    }
    public void ListBind()
    {
        this.newsmore.DataSource = CreateSource();
        this.newsmore.DataBind();        lbnNextPage.Enabled = false;
        lbnPrevPage.Enabled = true;
        if (CurrentPage == (PageCount - 1)) lbnNextPage.Enabled = false;
        if (CurrentPage == 0) lbnPrevPage.Enabled = false;
        lblCurrentPage.Text = (CurrentPage + 1).ToString();
    }
    public void Page_onClick(Object sender, CommandEventArgs e)
    {
        CurrentPage = (int)ViewState["PageIndex"];
        PageCount = (int)ViewState["PageCount"];        string cmd = e.CommandName;
        //判断cmd,以判定翻页方向 
        switch (cmd)
        {
            case "next":
                if (CurrentPage < (PageCount - 1)) CurrentPage++;
                break;
            case "prev":
                if (CurrentPage > 0) CurrentPage--;
                break;
        }        ViewState["PageIndex"] = CurrentPage;
        ListBind();
    }序后台: 

解决方案 »

  1.   

    晕,分个页这么难?1个分页存储过程1个页面中的分页控件 或者 js分页函数.cs中调用一下。例子很多,很多。
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
      {  PageSize = 20;
      ListBind();
      CurrentPage = 0;  ViewState["PageIndex"] = 0;
      //计算总共有多少记录  
      RecordCount = CalculateRecord();
      lblRecordCount.Text = RecordCount.ToString();  //计算总共有多少页  
      PageCount = RecordCount / PageSize + 1;
      lblPageCount.Text = PageCount.ToString();
      ViewState["PageCount"] = PageCount;
      }
    没加 ispostback吧7楼: 我们至少把代码看完了     你没看代码  更没资格说啥
      

  3.   

    怎么这么像JSP中的分页呢?我记得那个asp中分页不是挺简单的么