CurrentPageIndex是从零开始的呀,你看看记录有没有被删除?
加个异常处理。。

解决方案 »

  1.   

    http://lucky_elove.www1.dotnetplayground.com/
      

  2.   

    绑定的时候加上异常处理:
    //绑定
    operators.GetAllOperators(ref operatorDS);
    try
    {
    DataView Source = operatorDS.Tables["OPERATOR"].DefaultView;
    Source.Sort=sortField;
    dgOperatorAdmin.DataSource=Source;
    dgOperatorAdmin.DataBind();
    }
    catch(Exception e)
    {
    if(dgOperatorAdmin.CurrentPageIndex>=dgOperatorAdmin.PageCount)
    {
    int i=dgOperatorAdmin.CurrentPageIndex;
    i--;
    dgOperatorAdmin.CurrentPageIndex=i;

    if(dgOperatorAdmin.CurrentPageIndex<0)
    dgOperatorAdmin.CurrentPageIndex=0;
    dgOperatorAdmin.DataBind();
    }