473,473 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pagination problem with asp.net 1.1 datagrid

Hi all

Got a weird problem with pagination on a datagrid in asp.net 1.1.

It's populated depending on user selected criteria (it either displays all
or 1 record). It works fine in the following circumstances:

Datagrid populated with 1 record then re-populated with all
Datagrid populated with 1 record then re-populated with another single record
Datagrid populated with multiple records and displaying page 1 then
repopulated with 1 record

It falls over in the following circumstance:

Datagrid is populated with multiple records and displaying page 2 or 3 etc
then user attempts to repopulate with 1 record.

The error message is: Invalid CurrentPageIndex value. It must be >=0 and <
the PageCount. I'm guessing it's something to do with the fact that the
current page index is more than 0 and that confuses it, so I tried to reset
the pagecount to 0 but got a build error that pagecount is a readonly
property.

Here's the code:

Private Sub PartDataGrid_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
PartDataGrid.PageIndexChanged
‘This sub refreshes the datagrid if the page index is changed
PartDataGrid.CurrentPageIndex = e.NewPageIndex
If txtPartSearch.Text = "" Or txtPartSearch.Text = "(Enter part
number)" Then
showAllRecords()
Else
searchRecords()
End If
PartDataGrid.DataBind()
End Sub

Private Sub PartDataGrid_Page(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
PartDataGrid.CurrentPageIndex = e.NewPageIndex
PartDataGrid.DataBind()
End Sub

Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSearch.Click
‘This is what the user calls when pressing a search button to display 1 record
PartDataGrid.CurrentPageIndex = 0
End Sub

Private Sub cmdAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAll.Click
‘This is what the user calls when pressing a show all records button
PartDataGrid.CurrentPageIndex = 0
PartDataSet1.Clear()
strSQL = "SELECT * FROM PARTS"
Dim PartDataAdapter As New OleDb.OleDbDataAdapter
PartDataAdapter.SelectCommand = New OleDb.OleDbCommand(strSQL,
PartDbConnection)
PartDataAdapter.Fill(PartDataSet1, "Parts")
Session("PartDataSet") = PartDataSet1
PartDataGrid.DataBind()
End Sub

Private Sub searchRecords()
PartDataSet1.Clear()
Dim searchString As String = txtPartSearch.Text
Now run the search
strSQL = "Select * FROM Parts WHERE PartNo LIKE '" + searchString +
"'"
'now run the query using a data adapter
Dim PartDataAdapter As New OleDb.OleDbDataAdapter
PartDataAdapter.SelectCommand = New OleDb.OleDbCommand(strSQL,
PartDbConnection)
PartDataAdapter.Fill(PartDataSet1, "Parts")
Session("PartDataSet") = PartDataSet1
'This is where I get the error
PartDataGrid.DataBind()
End Sub

Thanks for your help.
Julia
Sep 30 '08 #1
2 1642
My apologies, I simplified the code from original and made a mistake. Please
see updated version below.

"Julia B" wrote:
Hi all

Got a weird problem with pagination on a datagrid in asp.net 1.1.

It's populated depending on user selected criteria (it either displays all
or 1 record). It works fine in the following circumstances:

Datagrid populated with 1 record then re-populated with all
Datagrid populated with 1 record then re-populated with another single record
Datagrid populated with multiple records and displaying page 1 then
repopulated with 1 record

It falls over in the following circumstance:

Datagrid is populated with multiple records and displaying page 2 or 3 etc
then user attempts to repopulate with 1 record.

The error message is: Invalid CurrentPageIndex value. It must be >=0 and <
the PageCount. I'm guessing it's something to do with the fact that the
current page index is more than 0 and that confuses it, so I tried to reset
the pagecount to 0 but got a build error that pagecount is a readonly
property.

Here's the code:

Private Sub PartDataGrid_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles PartDataGrid.PageIndexChanged
PartDataGrid.CurrentPageIndex = e.NewPageIndex
If txtPartSearch.Text = "" Or txtPartSearch.Text = "(Enter part
number)" Then
showAllRecords()
Else
searchRecords()
End If
End Sub

Private Sub PartDataGrid_Page(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
PartDataGrid.CurrentPageIndex = e.NewPageIndex
PartDataGrid.DataBind()
End Sub

Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSearch.Click
‘User clicks this button to select one record
PartDataGrid.CurrentPageIndex = 0
searchRecords()
End Sub

Private Sub cmdAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAll.Click
‘User clicks this button to select all records
PartDataGrid.CurrentPageIndex = 0
showAllRecords()
End Sub

Private Sub showAllRecords()
PartDataSet1.Clear()
strSQL = "SELECT * FROM PARTS"
Dim PartDataAdapter As New OleDb.OleDbDataAdapter
PartDataAdapter.SelectCommand = New OleDb.OleDbCommand(strSQL,
PartDbConnection)
PartDataAdapter.Fill(PartDataSet1, "Parts")
Session("PartDataSet") = PartDataSet1
PartDataGrid.DataBind()
End Sub

Private Sub searchRecords()
PartDataSet1.Clear()
Dim searchString As String = txtPartSearch.Text
'Now run the search
strSQL = "Select * FROM Parts WHERE PartNo LIKE '" + searchString +
"'"
'now run the query using a data adapter
Dim PartDataAdapter As New OleDb.OleDbDataAdapter
PartDataAdapter.SelectCommand = New OleDb.OleDbCommand(strSQL,
PartDbConnection)
PartDataAdapter.Fill(PartDataSet1, "Parts")
Session("PartDataSet") = PartDataSet1
'this is where the error occurs
PartDataGrid.DataBind()
End Sub
>
Thanks for your help.
Julia

Sep 30 '08 #2
Solved it - I had to set the current page index to 0 on the page load.

Julia

"Julia B" wrote:
Hi all

Got a weird problem with pagination on a datagrid in asp.net 1.1.

It's populated depending on user selected criteria (it either displays all
or 1 record). It works fine in the following circumstances:

Datagrid populated with 1 record then re-populated with all
Datagrid populated with 1 record then re-populated with another single record
Datagrid populated with multiple records and displaying page 1 then
repopulated with 1 record

It falls over in the following circumstance:

Datagrid is populated with multiple records and displaying page 2 or 3 etc
then user attempts to repopulate with 1 record.

The error message is: Invalid CurrentPageIndex value. It must be >=0 and <
the PageCount. I'm guessing it's something to do with the fact that the
current page index is more than 0 and that confuses it, so I tried to reset
the pagecount to 0 but got a build error that pagecount is a readonly
property.

Here's the code:

Private Sub PartDataGrid_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
PartDataGrid.PageIndexChanged
‘This sub refreshes the datagrid if the page index is changed
PartDataGrid.CurrentPageIndex = e.NewPageIndex
If txtPartSearch.Text = "" Or txtPartSearch.Text = "(Enter part
number)" Then
showAllRecords()
Else
searchRecords()
End If
PartDataGrid.DataBind()
End Sub

Private Sub PartDataGrid_Page(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)
PartDataGrid.CurrentPageIndex = e.NewPageIndex
PartDataGrid.DataBind()
End Sub

Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSearch.Click
‘This is what the user calls when pressing a search button to display 1 record
PartDataGrid.CurrentPageIndex = 0
End Sub

Private Sub cmdAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAll.Click
‘This is what the user calls when pressing a show all records button
PartDataGrid.CurrentPageIndex = 0
PartDataSet1.Clear()
strSQL = "SELECT * FROM PARTS"
Dim PartDataAdapter As New OleDb.OleDbDataAdapter
PartDataAdapter.SelectCommand = New OleDb.OleDbCommand(strSQL,
PartDbConnection)
PartDataAdapter.Fill(PartDataSet1, "Parts")
Session("PartDataSet") = PartDataSet1
PartDataGrid.DataBind()
End Sub

Private Sub searchRecords()
PartDataSet1.Clear()
Dim searchString As String = txtPartSearch.Text
Now run the search
strSQL = "Select * FROM Parts WHERE PartNo LIKE '" + searchString +
"'"
'now run the query using a data adapter
Dim PartDataAdapter As New OleDb.OleDbDataAdapter
PartDataAdapter.SelectCommand = New OleDb.OleDbCommand(strSQL,
PartDbConnection)
PartDataAdapter.Fill(PartDataSet1, "Parts")
Session("PartDataSet") = PartDataSet1
'This is where I get the error
PartDataGrid.DataBind()
End Sub

Thanks for your help.
Julia

Oct 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mukesh Kumar | last post by:
Hi, Can anybody throw some light about displaying records in datagrid and pagination will be done alphabetically. Like I want to click on G and want to display all the records starts with G. Is...
1
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
3
by: Joseph D. DeJohn | last post by:
I am trying to get pagination working on a datagrid. Can anyone point me to a resource for help on this? I'm not sure if custom paging is the best option or not.
0
by: Child | last post by:
I have a datagrid on which i would like a button column and pagination in the asp:datagrid tag i have the following code: onpageindexchanged="page_change" onitemcommand="gridact_itemcommand" ...
2
by: RB | last post by:
Hi All, The ASP.NET Datagrid's pagination capability allows me to display either the Next/Prev buttons or the Page numbers to allow the user to navigate through the datagrid page by page as...
0
by: Don Quijote de Nicaragua | last post by:
Hello chic@s, I have problem with pagination and procedure stored, can to show information within DataGrid, but when I do click in nobody of the number which they down appear for the pagination, do...
0
by: harish.c27 | last post by:
Hi folks!!! Can we implement pagination for DataGrid control in a Windows Forms (.net1.0- 2003) Application? Any code help will be useful. Thanks in advance. Harish
1
by: OceanBreeze | last post by:
I am new to .Net. I am using ASP 2.0 and C#. I want to pupolate a data grid programatically using the values obtained from a list conating domain objects. E.g., DAL.GetEmployee() returns a...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.