Hello
I have a DDL Category which list 3 categories.
When nothing is selected or ALL is selected, then it shows all the items in DataGrid.
If one category is selected, it autopostbacks and only these item of that category is shown in DataGrid.
This all works fine.
DataGrid has paging which works fine too.
Everything works good except one thing.
The "show all" page or first displayed page has 3 pages. When I am on the first page everything works but when I am on the 2nd page and I try to select category from DDL I get error:
Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount.
What does this mean?
Code:
Public Class Book
Inherits System.Web.UI.Page
Dim iSelect As String
Dim dsBookCategory As DataSet
Dim dsBook As DataSet
Dim dr As DataRow
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dsBookCategory = DB.GetBookDDLCategory
dsBook = DB.GetDGBook
If Not IsPostBack Then
Me.LoadddlCategory()
ddlBook.SelectedIndex = -1
dgBook.DataSource = dsBook
dgBook.DataBind()
Else
Me.DGLoad()
End If
End Sub
Private Sub LoadddlCategory()
ddlBook.Items.Add("All Books")
For Each dr In dsBookCategory.Tables("BookDDLCategory").Rows
ddlBook.Items.Add(dr("CategoryName"))
Next
ddlBook.DataBind()
End Sub
Private Sub DGLoad()
If ddlBook.SelectedIndex = 0 Then
dgBook.DataSource = dsBook
dgBook.DataBind()
Else
iSelect = ddlBook.SelectedValue
Dim dvBook As New DataView(dsBook.Tables("DGBook"))
dvBook.RowFilter = "CategoryName ='" & iSelect & "'"
dgBook.DataSource = dvBook
dgBook.DataBind()
End If
End Sub
Private Sub ddlBook_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgBook.SelectedIndexChanged
iSelect = ddlBook.SelectedItem.Value
End Sub
Private Sub dgBook_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles dgBook.PageIndexChanged
dgBook.CurrentPageIndex = e.NewPageIndex
dgBook.DataBind()
End Sub
Private Sub dgBook_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgBook.SelectedIndexChanged
End Sub
End Class
PLEASE HELP ME