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的值,如果不符合條件就會拋出異常,不會給下面的語句以執行的機會!