Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.

F

Franck

Hello,
in a datagrid, in the ItemDataBound event
in some cells a add some javascript that show up an information

strHref.Append("<A onclick=\"popupValid();\">");
strHref.Append("<span style=\"cursor:pointer\">");
strHref.Append(e.Item.Cells[1].Text+"</span></A>");

e.Item.Cells[1].Text=strHref.ToString();


if I had this when i ask for the next page (i'm using paging)
i recieve the following error

"Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. "

even if the values are the following:

datagrid.currentpageindex=1
datagrid.pagecount=2

-----code----
dgNivCompart.DataSource=tblCompart.DefaultView;
dgNivCompart.CurrentPageIndex=intPageIndexGridNivCompart;
int huio=dgNivCompart.PageCount;
dgNivCompart.DataBind();
-----code----

if i had nothing it work wells....
Am I missing something?
 
F

Franck

Phillip said:
What does your Javascript function popupValid() do?

only showing a popup with some info
no update, nothing...

function popupValidation()
{
var PopupWindow=null;
settings='width=250,height=172'
PopupWindow=window.open('Validation.aspx?','Confirm',settings);
PopupWindow.focus();
}


-- HTH, Phillip Williams http://www.societopia.net
http://www.webswapp.com "Franck said:
Hello,
in a datagrid, in the ItemDataBound event
in some cells a add some javascript that show up an information

strHref.Append("<A onclick=\"popupValid();\">");
strHref.Append("<span style=\"cursor:pointer\">");
strHref.Append(e.Item.Cells[1].Text+"</span></A>");

e.Item.Cells[1].Text=strHref.ToString();


if I had this when i ask for the next page (i'm using paging)
i recieve the following error

"Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. "

even if the values are the following:

datagrid.currentpageindex=1
datagrid.pagecount=2

-----code----
dgNivCompart.DataSource=tblCompart.DefaultView;
dgNivCompart.CurrentPageIndex=intPageIndexGridNivCompart;
int huio=dgNivCompart.PageCount;
dgNivCompart.DataBind();
-----code----

if i had nothing it work wells....
Am I missing something?
 
G

Guest

Franck said:
only showing a popup with some info
no update, nothing...

function popupValidation()
{
var PopupWindow=null;
settings='width=250,height=172'
PopupWindow=window.open('Validation.aspx?','Confirm',settings);
PopupWindow.focus();
}

If your analysis were correct (namely that removing this javascript fixes
the problem) then the Validation.aspx must be doing something that changed
the datasource data (and thereby affecting the page count on the rendered
grid. If on the other hand, validation.aspx is innocent of this suspicion
then you probably should step through the code carefully using the debugger
to find another analysis of the cause of the problem. The error that you are
getting usually happens with me when I databind the datagrid to a new dataset
that has lesser page count than the CurrentPageIndex.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com "Franck said:
Hello,
in a datagrid, in the ItemDataBound event
in some cells a add some javascript that show up an information

strHref.Append("<A onclick=\"popupValid();\">");
strHref.Append("<span style=\"cursor:pointer\">");
strHref.Append(e.Item.Cells[1].Text+"</span></A>");

e.Item.Cells[1].Text=strHref.ToString();


if I had this when i ask for the next page (i'm using paging)
i recieve the following error

"Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. "

even if the values are the following:

datagrid.currentpageindex=1
datagrid.pagecount=2

-----code----
dgNivCompart.DataSource=tblCompart.DefaultView;
dgNivCompart.CurrentPageIndex=intPageIndexGridNivCompart;
int huio=dgNivCompart.PageCount;
dgNivCompart.DataBind();
-----code----

if i had nothing it work wells....
Am I missing something?
 
Joined
Jun 29, 2007
Messages
2
Reaction score
0
Hi,
I had faced similar problem in my datagrid. In my datagrid there was a column of hyperlinks. I was setting the NavigateUrl property of those hyperlinks in the ItemDataBound event of Datagrid. The NavigateUrl property was thus set to a Javascript function which opened a pop-up window. When I actually clicked a link to open a pop-up window, then after closing the window I found that DataGrid paging on the original page was giving an InvalidCurrentPage index value error. After some R & D I found that opening the pop-up window somehow changed the PageCount value. But we cant manipulate this value in the PageIndexChanged event as it is a ReadOnly property. Then I figured out that since I was calling the function that was returnng a Dataset in the PageIndexChanged event, this problem was occuring. To solve it, I moved that function to Page_Load event and in PageIndexChanged event only the code that resets the CurrentPageIndex was retained. And then,....it worked.

With Regards,
Sangharsh Sharma
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top