Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repopulating a datagrid with page index problem.

Status
Not open for further replies.

FoxT2

MIS
Oct 3, 2003
143
US
Hello,

I have a datagrid on a webform that I repopulate based on user input on the form. The problem is that sometimes when I repopulate the grid it errors on my databind property with this error...

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

This is the code I execute each time I repopulate my grid. The strSQL string is different based on the user input.

***
With DataGrid1
.DataSource = CreateDataSet(strSQL)
.DataBind()
End With
***

The only thing I think it may be is that the grid somehow needs to be reset before I repopulate it in order to have the correct currentpageindex value. Any help on this would be appreciated.

Thanks,

FoxT
 
you probably use pages to display the information. this propery is saved in the view state which means that on subsequent displays, the datagrid uses the last pageindex that was displayed. i recommend that you set the CurrentPageIndex to 0 when you rebind the datagrid because of the user input change

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Dazzled, I was thinking the same thing and did try setting the CurrentPageIndex = 0 before re-binding the grid, however I still have this same problem. I think some other property as well may need to be reset also. To add just a little more information to the problem, it seems that the entire page count is effected also. Because I notice that sometimes when I rebind my grid it will display a different amount of page choices than it really should. For instance, I now on a perticular choice that only 3 pages of data should be bound although the grid displays 10 or more page options in which selected by the user results in an error. I am going to try clearing the pagecount propery next and see if my results are better. Other than that I am still not sure what the problem is. I may just code the pages myself by allowing custom paging if I spend anymore time on this problem.

Thanks for the response,

FoxT
 
i had same issue, but now fixed, heres what i did...
Code:
    Sub MasterGrid_Page(Sender As Object, E As DataGridPageChangedEventArgs)
    	MasterGrid.SelectedIndex = 0
       	MasterGrid.CurrentPageIndex = e.NewPageIndex
       	BindMasterGrid()
    End Sub

what it acutally is mostly is if a user selects the last item in the list, then pages to a page that does not have that many records, it will give that error. setting the currentpageindex = 0 will cause your page to fail creating many extra page numbers.

and be careful if your using master-child dg's to reset the selectedindex = 0 so the DataKey will load.
 
also take a look at the datasource of the datagrid. if it's a dataview, look to see if you have any row filters

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top