判断一下DataGrid:
if((System.Convert.ToInt32(this.LabRecordCount.Text.Trim())-CheckCount)%10 == 0 && this.DGridEXAM_QUESTION.CurrentPageIndex != 0)
{
this.DGridEXAM_QUESTION.CurrentPageIndex = this.DGridEXAM_QUESTION.CurrentPageIndex-1;
}
意思就是,如果删除了最后一页的所有记录,则DataGrid的当前页必须减1,就不会报错了.

解决方案 »

  1.   

    也就是在你的dGridUser_DeleteCommand事件中进行判断.
      

  2.   

    下面是个简单的例子:SQLStatement="SELECT cnid, cnname, groupname FROM V_cnGroup GROUP BY cnid, cnname, groupname "+sqlstr+" ORDER BY cnid DESC";DataView dv=cService.SelectDataSet(SQLStatement,"V_cnGroup").Tables["V_cnGroup"].DefaultView;
    MyDataGrid.DataSource=dv;
    if(dv.Count % MyDataGrid.PageSize ==0)
    {
    iPagecount=dv.Count/MyDataGrid.PageSize;
    }
    else
    {
    iPagecount=dv.Count/MyDataGrid.PageSize+1;
    }
    if(iPagecount>iPageindex)
    {
    MyDataGrid.DataBind();
    }
    else
    {
    if(iPagecount>0)
    {
    MyDataGrid.CurrentPageIndex=iPagecount-1;
    }
    else
    {
    MyDataGrid.CurrentPageIndex=0;
    }
    MyDataGrid.DataBind();
    }
      

  3.   

    dGridUser_DeleteCommand事件中添加一下代码:
    int int_PageLess;
    if(this.dGridUser.CurrentPageIndex == this.DGrid_Process.PageCount-1)
    {
    if(this.dGridUser.CurrentPageIndex == 0)
    {
    this.dGridUser.CurrentPageIndex = this.dGridUser.PageCount - 1;   
    }
    else
    {
    if(this.dGridUser.Items.Count % this.dGridUser.PageSize == 1)
    {
    int_PageLess = 2;
    }
    else
    {
    int_PageLess = 1;
    }
    this.DGrdGridUser.CurrentPageIndex = this.dGridUser.PageCount - int_PageLess;
    }
    }
      

  4.   

    如果是在最后一页,必须判断删除记录后最后一页还剩几条记录
    如果最后一页只有一条记录,删除后,DataGrid的CurrentPageIndex要减去2