ASP.NET關於分頁上的資料刪除問題

來源:互聯網
上載者:User
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的值,如果不符合條件就會拋出異常,不會給下面的語句以執行的機會!



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.