Hi,
I am working in VS2005 (VB) environment and I have following problem:
On one of my web pages I use Datagrid control which I dynamically load.
I
also use numerical paging with Datagrid. After choosing one item in
Datagrid
and going to another web page, and returning on the page with Datagrid
with
IE "previous page" button, I try to choose another page in Datagrid but
I
recieve following error:
Exception Details: System.Web.HttpException: Invalid CurrentPageIndex
value.
It must be >= 0 and < the PageCount.
Source Error:
Line 136: Public Sub BindGrid()
Line 137: MyDataGrid.DataSource = CreateDataSource()
Line 138: MyDataGrid.DataBind()
Line 139: End Sub
Line 140:
Somewhere CurrentPageIndex value gets changed and I don't know where or
why
that happened. I am using Datagrids on other pages but with other
names.
Thanks in advance for any kind of help!
I used following code from VS2005 documentation as example:
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<html>
<script language="VB" runat="server">
Function CreateDataSource() As ICollection
Dim dt As New DataTable()
Dim dr As DataRow
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("DateTimeValue",
GetType(String)))
dt.Columns.Add(New DataColumn("BoolValue", GetType(Boolean)))
Dim i As Integer
For i = 0 To 99
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " & i.ToString()
dr(2) = DateTime.Now.ToShortDateString()
If i Mod 2 <0 Then
dr(3) = True
Else
dr(3) = False
End If
dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource
Sub Page_Load(sender As Object, e As EventArgs)
BindGrid()
End Sub 'Page_Load
Sub MyDataGrid_Page(sender As Object, e As
DataGridPageChangedEventArgs)
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub 'MyDataGrid_Page
Sub BindGrid()
MyDataGrid.DataSource = CreateDataSource()
MyDataGrid.DataBind()
End Sub 'BindGrid
</script>