Asp.net| Page | data | Problem when you delete data on the last page, the situation is when you delete all the data from the last page, and then there are
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" 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
The reason is currentpageindex==pagecount!
The hint here is CurrentPageIndex must be >=0 and Pagecount<pagecount.
So the solution is to change the current CurrentPageIndex value, set it to 0 (the first page) or any value less than PageCount. I tried the following methods to solve the problem without success:
Datagrid1.pagecount=1; Here PageCount is not to be changed!!!
Datagrid1.currentpageindex-=1; First-1
/*if (datagrid1.pagecount-datagrid1.currentpageindex>1)
{datagrid1.currentpageindex+=1; }*/
If they are judged to be eligible again +1, because CurrentPageIndex must be less than PageCount, so first-1, but this method is not implemented, May be after the execution of the Delete this action will immediately check the value of CurrentPageIndex and PageCount, if not meet the criteria will throw an exception, will not give the following statement to execute the opportunity!