Solved

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

Posted on 2004-08-17
5
704 Views
Last Modified: 2010-04-07
Hello, i have a simple product catalogue in which the user enters a search word and the server returns a list of possible matches. I also have paging enabled in this datagrid. When you page to say.. page 4, and then search for a different term, if the new term does not fill 4 pages, it throws this error. How can i reset the page index to 1, whenever the user searches for a new key word?
0
Comment
Question by:danimbrogno
5 Comments
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 11820950
Set it to 0, remember you are dealing with indexes (which start at 0) as opposed to counts (which start with 1).  It gets confusing at first, just remember that indexes are usually always 1 less than the count, so if you are at page 4, the currentpageindex is 3.
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11820962
0
 
LVL 9

Expert Comment

by:crescendo
ID: 11820972
Just do

    YourGrid.CurrentPageIndex = 0

to set it back to page 1.
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11820974
You can check to see how many rows you have in the DataSet tables and then enable disable the paging:
Assuming I set paging for more than 20 items then

If MyDataSet.Tables["MyTable"].Rows.Count < 20 then

MyDataGrid.AllowPaging = false

else

MyDataGrid.AllowPaging = true

end if

MyDataGrid.DataSource = MyDataSet.Tables["MyTable"];
MyDataGrid.DataBind();

Always remember to enable/disable the paging before you bind the datagrid.

Best, nauman
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11820977
raterus is correct here is an example:

 Private Sub SearchProducts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchProducts.Click
        Dim Query As String
        Query = "SELECT * FROM sschecter.JobNumbers JN WHERE "
        Select Case FieldsToMatch.SelectedValue
            Case "JobNumber"
                Query &= "JN.JobNumber LIKE '%" & SearchQuery.Text & "%'"
            Case "CustomerID"
                Query &= "JN.CustomerID LIKE '%" & SearchQuery.Text & "%'"
            Case "Either"
                Query &= "JN.JobNumber LIKE '%" & SearchQuery.Text & "%' " & _
                "OR JN.CustomerID LIKE '%" & SearchQuery.Text & "%'"
        End Select
        Query &= " ORDER BY JN.JobNumber DESC"
        dg.CurrentPageIndex = 0    ******************************************
        BindTheData(Query)
        FullQuery.Value = Query
    End Sub

Regards,

Aeros
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now