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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid PageIndex

Status
Not open for further replies.

cyberdeminout

Programmer
Jul 19, 2005
37
US
I have datagrid (total records 7) and pagesize is 6 and pager style is numeric and two columns (name column and checkbox column and all are checked)

by default, currentpageindex is 0 and 1st page have first 6 records appearing and clicked on 2nd page(pageindex 1) and it shows 7th record. when uncheck 7th checkbox(2nd page) and click on save button, saving user selection to Database and populating grid again(It saves Perfectly).

now total record count is 6 and current pageindex should be 0. but page index is not changing and remains 1 and I gotta error for this case.

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

Can anybody help?

Thanks

 
the page index won't change automatically. You will have to check the # of records that are now being bound to the grid and set the pageindex accordingly.
Something like this
Code:
If totalrows/pagesize > currentpageindex then
  pageindex = currentpageindex -1
End IF
However if you delete a number of rows > pagesize then you will still get an error. I would just use the calulation above, and if > currentpageindex, set the pageindex = 0. This way you will always be set to the first page.

Jim
 
i tested following calculation and is working fine.

If dtSelectedInstitutions.Rows.Count > 6 Then
If dtSelectedInstitutions.Rows.Count / 6 > dgSI.CurrentPageIndex Then
sPageIndex = dgSI.CurrentPageIndex - 1
If sPageIndex = -1 Then dgSI.CurrentPageIndex = 0
Else
dgSI.CurrentPageIndex = dgSI.CurrentPageIndex - 1
End If
Else
dgSI.CurrentPageIndex = 0
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top