ASP.NET关于分页上的数据删除问题

80酷酷网    80kuku.com

  asp.net|分页|数据|问题当在最后一页删除数据的时候,情形是删除了最后一页的所有数据,那么会出现

Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount
 

原因是CurrentPageIndex==PageCount!

这里的提示是CurrentPageIndex must be >=0  and PageCount<PageCount.

所以解决方法就是改一下当前 CurrentPageIndex 的值,把它设置为0(第一页)或任何小于PageCount的值.我尝试了以下的方法解决没有成功:

//DataGrid1.PageCount=1;  这里PageCount是不可以更改的!!!

//DataGrid1.CurrentPageIndex-=1;  先-1

/*if(DataGrid1.PageCount-DataGrid1.CurrentPageIndex>1)

 {   DataGrid1.CurrentPageIndex+=1;             }*/

  如果判断他们符合条件再+1,因为CurrentPageIndex必须小于PageCount, 所以要先-1,但是此方法不能实现,可能是执行完删除这个动作马上就会检查CurrentPageIndex的值和PageCount的值,如果不符合条件就会抛出异常,不会给下面的语句以执行的机会!

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: