Solved

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

Posted on 2004-08-17
5
709 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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