kdeutsch
asked on
Invalid CurrentPageIndex value
It was working fine and then boom all the sudden started to get this message. I have not enabled anthing in the datagrid to be deleted or updated yet, the error starts from the page load. When i click on a page number it throw the error.
Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
I have looked at several solution but non seem to work, don't know why. the follwoing is my code for my pageindexchanged. I added the if then else statment to try to resolve issue but I still get the error.
Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
I have looked at several solution but non seem to work, don't know why. the follwoing is my code for my pageindexchanged. I added the if then else statment to try to resolve issue but I still get the error.
Private Sub myDataGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles myDataGrid.PageIndexChanged
'Enable datagrid paging
If myDataGrid.CurrentPageIndex >= myDataGrid.PageCount Then
myDataGrid.CurrentPageIndex = myDataGrid.PageCount - 1
End If
myDataGrid.CurrentPageIndex = e.NewPageIndex
myDataGrid.DataSource = myDataTable
myDataGrid.DataBind()
End Sub
Please verify that myDataTable contains records that you want to display.
For example myDataTable should not be null or it should not changed. Like previously it has 100 records and now it has only 20 records . So if you give new page index and that out of scope so that error occur.
For example myDataTable should not be null or it should not changed. Like previously it has 100 records and now it has only 20 records . So if you give new page index and that out of scope so that error occur.
ASKER
lppperes,
That is what I originally started with but since I am still using asp.net 1.1 I need to use as such. It wa working then all the sudden stopped working, they do not have an ability to delete any of the files. Paging does not work from the start.
myDataGrid.CurrentPageInde x = e.NewPageIndex
myDataGrid.DataSource = myDataTable
myDataGrid.DataBind()
jinal,
Not sure what you are talking about. It show the records, same amount as before but paging just stopped working.
That is what I originally started with but since I am still using asp.net 1.1 I need to use as such. It wa working then all the sudden stopped working, they do not have an ability to delete any of the files. Paging does not work from the start.
myDataGrid.CurrentPageInde
myDataGrid.DataSource = myDataTable
myDataGrid.DataBind()
jinal,
Not sure what you are talking about. It show the records, same amount as before but paging just stopped working.
Make sure you don't rebind the DataGrid upon postback, which means you have a "If Not IsPostBack Then" block in Page_Load.
ASKER
HI,
this is the only code I have in postback statement, so are you saying I need to put the rebind in my postback. Right now I am just filling a dropDown list. Attached is all my code behind.
Help.txt
this is the only code I have in postback statement, so are you saying I need to put the rebind in my postback. Right now I am just filling a dropDown list. Attached is all my code behind.
Help.txt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
OK I changed the bind as recommended with this statement added
ViewState(sql) = myDataTable
But I am getting blue underlines with this statement in the pageIndexChanged statement
MyDataTable = (DataTable)ViewState("Sql" )
Get Seperate blue underlines under Datable and ViewState
DataTable is a type and cannot be used as expression
End of satement expected
If I put in the "" in Daatable as such ("DataTable")
then i get on error
End of Statement expected
OK I changed the bind as recommended with this statement added
ViewState(sql) = myDataTable
But I am getting blue underlines with this statement in the pageIndexChanged statement
MyDataTable = (DataTable)ViewState("Sql"
Get Seperate blue underlines under Datable and ViewState
DataTable is a type and cannot be used as expression
End of satement expected
If I put in the "" in Daatable as such ("DataTable")
then i get on error
End of Statement expected
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also keep in mind that ViewState is case sensitive, which means ViewState("sql") is not the same as ViewState("Sql")
ASKER
prairiedog,
Ok did not get the error but my datagrid disappeared. Do I need to put this in my Postback load event
Ok did not get the error but my datagrid disappeared. Do I need to put this in my Postback load event
Post your current code please. It seems to me that myDataTable is empty.
ASKER
Hi prairiedog,
I figured it out by looking at you past posts and making sure everything was same, I missed the "" around my dataFill. One question though, now I need to start saving data in the grid to a DB with other information and I will start taking rows out of the datagrid. Will this code still work??
I figured it out by looking at you past posts and making sure everything was same, I missed the "" around my dataFill. One question though, now I need to start saving data in the grid to a DB with other information and I will start taking rows out of the datagrid. Will this code still work??
>>now I need to start saving data in the grid to a DB with other information and I will start taking rows out of the datagrid.
Can you elaborate a bit?
Can you elaborate a bit?
ASKER
HI,
I was babbling on, want the intent is that I search for a name in a db and save it to a specific row of the datagrid, when i do this I need to reload the datagrid. Will this have an effect on the page index event.
I was babbling on, want the intent is that I search for a name in a db and save it to a specific row of the datagrid, when i do this I need to reload the datagrid. Will this have an effect on the page index event.
ASKER
Thanks for everyones help
It depends.
If you can ask a related question, then it will easier for us to understand your question better.
If you can ask a related question, then it will easier for us to understand your question better.
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = myDataTable
GridView1.DataBind();