Solved

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

Posted on 2004-08-17
5
701 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

21 Experts available now in Live!

Get 1:1 Help Now