Paging Index Error
Hi All,
Sorry to have to hash this one out again cause I've seen a lot of postings on this topic. I've looked through all the postings and tried the suggestions but still have not been able to resolve this. I know what the problem is but can't seem to find a solution.
The paging is on a search page that is driven by three drop-down lists. When the search results in less pages than the previous search and the page index is higher than the number of pages in the new recordset, I'm getting the this error.
Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
Sub getProducts(ByVal s As Object, ByVal e As EventArgs)
Dim SQL As String = "SELECT Manufacturers.ManName, Products.ProdID, Products.ProdName, Products.ProdDesc, Products.ProdYear, Products.ProdPrice, Products.ProdSold FROM Products INNER JOIN Manufacturers ON Manufacturers.ManID = Products.ManID INNER JOIN Subcategories ON Subcategories.SubID = Products.SubID WHERE
Manufacturers.Status > 0 AND Products.Status > 0 "
If ddlCatID.SelectedValue > 0 Then
SQL += "AND Subcategories.CatID = " & ddlCatID.SelectedValue & " "
If ddlSubID.SelectedValue > 0 Then
SQL += "AND Products.SubID = " & ddlSubID.SelectedValue & " "
End If
End If
If ddlManID.SelectedValue > 0 Then
SQL += "AND Products.ManID = " & ddlManID.SelectedValue & " "
End If
If Len(txtProdName.Text) > 0 Then
SQL += "AND Products.ProdName LIKE '%" & txtProdName.Text & "%' "
End If
SQL += "ORDER BY Products.ProdDate DESC;"
Dim oDA As New SqlDataAdapter(SQL, _oConn)
Dim oDS As New DataSet
oDA.Fill(oDS)
grdProducts.DataSource = oDS
grdProducts.DataBind()
End Sub
Sub pageProducts(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs)
grdProducts.CurrentPageIndex = e.NewPageIndex
If grdProducts.CurrentPageIndex > grdProducts.PageCount Or grdProducts.CurrentPageIndex >
grdProducts.PageCount Then
grdProducts.CurrentPageIndex = 0
End If
getProducts(s, e)
End Sub
Any help on this would be greatly appreciated.
Thanks,
Richard
|