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
Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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