J
Julia B
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.DataGridPageChangedEventArgs) 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
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.DataGridPageChangedEventArgs) 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