Padding Padding
Janet
Systems
 Register  Login 
Telephone  01628 566 178
Website Design, Hosting and Software Services
  Search 
Padding
corner Padding corner
Padding Padding
corner Padding corner
 ASP.NET Articles

I recently received this error whilst working with a datagrid

DotNetNuke.Services.Exceptions.ModuleLoadException: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. ---> System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. at

I had implemented a search on the data, which could be called after the entries in the datagrid had been paged. This meant that the page reference for the datagrid could be, say 7, whilst slearly the result from the search is likely to be page 1.

Having implemented the paging code:

      Private Sub grdListItem_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles grdListItem.PageIndexChanged
         grdListItem.CurrentPageIndex = e.NewPageIndex
         BindData(txtSearch.Text, ddlSearchType.SelectedIndex.ToString)
      End Sub


The first obvious step was to modify that and set it to page 1. Afterall, it was a figure 1 that I was seeing at the bottom of the datagrid for the page number.

Further investigation led me to understand that whilst the displayed page numbers start at 1 and work upwards, in reality they follow the usual array convention by being handled from 0 upwards. Therefore my solution was:

      Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnSearch.Click
         grdListItem.CurrentPageIndex = 0
         grdListItem.PageSize = CType(ddlRecordsPerPage.SelectedItem.Text, Integer)
         BindData(txtSearch.Text, ddlSearchType.SelectedItem.Value)
      End Sub

NAT July 2005 (Revised)


This article viewed: 5411 times Back

Copyright © 2004-2007 Janet Systems Ltd.

 Print   

DotNetNuke Website design and hosting from £15.00 per month. More...

Looking for a website design company in the Thames Valley, call us on 01628 566178

DotNetNuke Modules
DotNetNuke Modules availalble from Janet Systems

DotNetNuke Skins
DotNetNukeSkins.gif

from Janet Systems

Padding
Copyright 2002-2008 Janet Systems Ltd.   Terms Of Use  Privacy Statement Tuesday, May 13, 2008