Monday, July 28, 2008

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

Two Datagrid refering to one OnPageIndexChanged Sub. Example. Datagrid A has 1 page only. Datagrid B has 2 page. When try to go to page B's 2nd page, error occur. Because the OnPageIndexChanged Sub will call Datagrid A's 2nd page which does't exist.

Solution:
Create two different OnPageIndexChanged Sub. Make sure the name are different. Example code:

The Datagrid
< id="Datagrid1" runat="server">
AllowPaging="True" AutoGenerateColumns="False"
OnPageIndexChanged="NewPageClick" PageSize="10">

The Sub
Sub NewPageClick(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs) Datagrid1.CurrentPageIndex = e.NewPageIndex
End Sub
.

No comments: