Solved

DataGrid PageIndexing (.NET1.1)

Posted on 2009-07-02
4
217 Views
Last Modified: 2012-05-07
I have an datagrid populated on load of form. It works pretty well. I can go to different pages .
I have a search criteria textbox on the same form. Based on the search criteria i re-poulate my datagrid with the new result. But if i am on any other page of datagrid rather then the first page then i get the below error. How do i handle this issue?

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.


private void grdStandard_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
                      grdStandard.CurrentPageIndex = e.NewPageIndex;
                      grdStandard.DataSource= CreateDataSource();
	grdStandard.DataBind();
		
}

Open in new window

0
Comment
Question by:SajRuki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
tpsl earned 500 total points
ID: 24763960
Yup that is an issue with the datagrid control of 1.1.

What u'll have to do is place the code to bind in a try catch block.

In the catch block u'll have to write

like this
try
{
 
}
catch(Exception ex)
{
      if(ex.Message = "Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.")
      {
            grdStandard.CurrentPageIndex = 0;
            grdStandard.DataSource= CreateDataSource();
            grdStandard.DataBind();
 
      } 
}

Open in new window

0
 

Author Comment

by:SajRuki
ID: 24778901
I tried the above code. It still throws the same error. Also tried to catch the HttpException instead of generic exception, but still it does not work.
0
 

Author Comment

by:SajRuki
ID: 24778945
It worked fine. Thanx a lot for the solution.
0
 

Author Closing Comment

by:SajRuki
ID: 31599206
Thanx...
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question