473,473 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems with paging in Datagrid

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>

Sep 9 '06 #1
0 884

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RelaxoRy | last post by:
sqlConnection1.Open(); myReader = sqlCommand1.ExecuteReader(); DataGrid1.DataSource = myReader; DataGrid1.DataBind(); myReader.Close(); sqlConnection1.Close(); The Datagrid populates fine. ...
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
2
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
2
by: Axel Dahmen | last post by:
Hi, I'm using a DataGrid control to show a table's content with paging. For navigation through the pages I'm using the DataGrid's intrinsic navigation section. My problem: The DataGrid...
0
by: Pat | last post by:
I have 3 Datagrid nested. Master Details Child The master has paging (And i'm using the paging inbuilt in the Datagrid) in the Master DataGrid you select a linkbutton(using commandname) and it...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
5
by: Donald Adams | last post by:
Hi, I will have both web and win clients and would like to page my data. I could not find out how the datagrid control does it's paging though I did find some sample code that says they do it...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.