How can I fix error message ‘Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount'

Platform: ASP.NET| Category: DataGrid

There are two approaches to fix this error:

  • Set the CurrentPageIndex = 0 when you bind data in the Page_EventHandler
  • Allow the error to occur and then catch it in a try block resetting the index to 0 and rebinding the grid

    VB.NET

    
    try
    	’Bind the Data
    catch ex as ArgumentOutOfRangeException
    	DataGrid1.CurrentPageIndex  = 0;
    	’Bind the Data
    end try
    

    C#

    
    try
    {
    	//Bind the Data
    }
    catch(ArgumentOutOfRangeException ex )
    { 
    	DataGrid1.CurrentPageIndex  = 0;
    	//Bind the Data
    }
    
    

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.