Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2006, 12:49 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default Paging Index Error

Hi All,

Sorry to have to hash this one out again cause I've seen a lot of postings on this topic. I've looked through all the postings and tried the suggestions but still have not been able to resolve this. I know what the problem is but can't seem to find a solution.

The paging is on a search page that is driven by three drop-down lists. When the search results in less pages than the previous search and the page index is higher than the number of pages in the new recordset, I'm getting the this error.

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

Sub getProducts(ByVal s As Object, ByVal e As EventArgs)
        Dim SQL As String = "SELECT Manufacturers.ManName, Products.ProdID, Products.ProdName, Products.ProdDesc, Products.ProdYear, Products.ProdPrice, Products.ProdSold FROM Products INNER JOIN Manufacturers ON Manufacturers.ManID = Products.ManID INNER JOIN Subcategories ON Subcategories.SubID = Products.SubID WHERE
Manufacturers.Status > 0 AND Products.Status > 0 "
        If ddlCatID.SelectedValue > 0 Then
            SQL += "AND Subcategories.CatID = " & ddlCatID.SelectedValue & " "
            If ddlSubID.SelectedValue > 0 Then
                SQL += "AND Products.SubID = " & ddlSubID.SelectedValue & " "
            End If
        End If
        If ddlManID.SelectedValue > 0 Then
            SQL += "AND Products.ManID = " & ddlManID.SelectedValue & " "
        End If
        If Len(txtProdName.Text) > 0 Then
            SQL += "AND Products.ProdName LIKE '%" & txtProdName.Text & "%' "
        End If
        SQL += "ORDER BY Products.ProdDate DESC;"
        Dim oDA As New SqlDataAdapter(SQL, _oConn)
        Dim oDS As New DataSet
        oDA.Fill(oDS)
        grdProducts.DataSource = oDS
        grdProducts.DataBind()
    End Sub

Sub pageProducts(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs)
        grdProducts.CurrentPageIndex = e.NewPageIndex
        If grdProducts.CurrentPageIndex > grdProducts.PageCount Or grdProducts.CurrentPageIndex >

grdProducts.PageCount Then
            grdProducts.CurrentPageIndex = 0
        End If
        getProducts(s, e)
    End Sub

Any help on this would be greatly appreciated.

Thanks,
Richard



 
Old February 1st, 2006, 12:53 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Richard,

Didn't this post help: http://p2p.wrox.com/topic.asp?TOPIC_ID=39379 ?

Imar
 
Old February 1st, 2006, 02:41 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi Imar,

OK. I think its fixed. So far sooooo good.

I created a copy of getProducts, a duplicate sub called gettheProducts that fires on the button click event and added the line:

grdProducts.CurrentPageIndex = 0

So that everytime there is a new dataset the CurrentPageIndex = 0, which is what should happen anyway.

Changed Sub pageProducts to fire the other Sub getProducts.

    Sub pageProducts(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs)
        grdProducts.CurrentPageIndex = e.NewPageIndex
        getProducts()
    End Sub

IT'S ALIIIIIIIIIIIIVE!!!!!!!!!!!!!!!!!!

Thank you oh so much Imar. Very much appreciated. I'm going to go buy a bottle of aquavit and celebrate now.

Richard







Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined Index Error rit01 Beginning PHP 0 March 1st, 2006 10:03 AM
Paging Problem Revisited - Index Error rstelma General .NET 9 February 3rd, 2006 07:10 PM
Page index error lily611 General .NET 7 August 31st, 2004 11:19 AM
Error about paging Blueman137 VS.NET 2002/2003 1 January 7th, 2004 11:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.