我使用datagrid自带的分页,我定义数值按钮是20,现在问题是如果我点击1-20索引后面的省略号号,跳到21-40那个页面,我点了21,他怎么重新回到1-20的那个页面,数据也是1-20索引的数据,而不是21页后面的数据,请问是为什么??
下面是我分页事件写的代码(使用组件的)
private void sbInfo_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
string sbwb=Request["sb"];
obj.ConnectionString =strconnection;
ds=obj.GetSBInfoWithSQL(sbwb);
sbInfo.CurrentPageIndex = e.NewPageIndex;
sbInfo.DataSource = ds;
sbInfo.DataBind();
}

解决方案 »

  1.   

    建议不要使用自带的分页功能,而是使用成品组件,比如:
    aspnetpager
    你可到如下地址下载
    www.webdiyer.com
      

  2.   

    //****************************************************分页时,改变行号
    int int_PageLess; //定义页面跳转的页数
    //如果当前页是最后一页
    if(this.DataGrid1.CurrentPageIndex == this.DataGrid1.PageCount-1)
    {
    //如果就只有一页
    if(this.DataGrid1.CurrentPageIndex == 0)
    {
    //删除后页面停在当前页
    this.DataGrid1.CurrentPageIndex = this.DataGrid1.PageCount-1;   
    }
    else
    {
    //如果最后一页只有一条记录
    if((this.DataGrid1.Items.Count % this.DataGrid1.PageSize == 1) || this.DataGrid1.PageSize == 1)
    {
    //把最后一页最后一条记录删除后,页面应跳转到前一页
    int_PageLess = 2;
    }
    else      //如果最后一页的记录数大于1,那么在最后一页删除记录后仍然停在当前页
    {
    int_PageLess = 1;
    }
    this.DataGrid1.CurrentPageIndex = this.DataGrid1.PageCount - int_PageLess;
    }

    }
    MyBind();