Invalid CurrentPageIndex error

S

Spike

Hi all,
Invalid CurrentPageIndex error seems to occur even when
CurrentPageIndex is set to zero just before binding the
datagrid. Can anyone provide any more insights on this
problem. Thanks in advance.
 
S

Spike

I have read the article and tried handling the exception
but I still get the error. I can mail you the code if
required.
-----Original Message-----
see this article
http://support.microsoft.com/default.aspx?scid=kb;en- us;555074

You say you are setting currentpageindex = 0 right before you bind and still
getting the error?

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
Hi all,
Invalid CurrentPageIndex error seems to occur even when
CurrentPageIndex is set to zero just before binding the
datagrid. Can anyone provide any more insights on this
problem. Thanks in advance.


.
 
A

Alvin Bruney [MVP]

post the relevant portions of the code

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
I have read the article and tried handling the exception
but I still get the error. I can mail you the code if
required.
-----Original Message-----
see this article
http://support.microsoft.com/default.aspx?scid=kb;en- us;555074

You say you are setting currentpageindex = 0 right before you bind and still
getting the error?

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
Hi all,
Invalid CurrentPageIndex error seems to occur even when
CurrentPageIndex is set to zero just before binding the
datagrid. Can anyone provide any more insights on this
problem. Thanks in advance.


.
 
S

Spike

Here is the WebForm
-------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb"
Inherits="DataGridPageProblem.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio.NET
7.0" name="GENERATOR">
<meta content="Visual Basic 7.0"
name="CODE_LANGUAGE">
<meta content="JavaScript"
name="vs_defaultClientScript">
<meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post"
runat="server">
<asp:DataGrid id="DataGrid1"
runat="server" PageSize="10" Height="0px" Width="100%"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="0">
<SelectedItemStyle Font-
Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle
ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-
Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<Columns>
<ASP:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="Last Name"></ASP:BoundColumn>
<ASP:BoundColumn
DataField="Title" SortExpression="Title"
HeaderText="Title" Visible="False"></ASP:BoundColumn>
<ASP:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="First Name"></ASP:BoundColumn>
</Columns>
<PagerStyle Font-
Bold="True" HorizontalAlign="Right" ForeColor="#330099"
BackColor="#FFFFCC" Mode="NumericPages"></PagerStyle>
</asp:DataGrid><BR>
</form>
</FORM></FORM>
</body>
</HTML>
---------------------------------------
Here is the code behind
----------------------------
Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid

Private Const mstrAlphaPageCommand = "AlphaPage"
Private mstrAlphaPageList As String
= "A,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
Private mConnectionString As String = "Password=;User
ID=sa;Data Source=<<datasource>>;Initial Catalog=Northwind"

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web
Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub

Sub BindGrid(Optional ByVal alpha As String = "")
Dim cnn As New SqlConnection(mConnectionString)
Dim da As SqlDataAdapter
If alpha = "" Then
'da = New SqlDataAdapter("select
title,lastname,firstname from employees where lastname
like 'D%'", cnn)
da = New SqlDataAdapter("select
title,lastname,firstname from employees", cnn)
Else
da = New SqlDataAdapter("select
title,lastname,firstname from employees where lastname
like '" & LCase(alpha) & "%'", cnn)
End If
Dim ds As New DataSet()
da.Fill(ds, "employees")
DataGrid1.DataSource = ds
DataGrid1.CurrentPageIndex = 0
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_SelectedIndexChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles DataGrid1.SelectedIndexChanged

End Sub

Private Sub DataGrid1_PageIndexChanged(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub

Private Sub DataGrid1_ItemCommand(ByVal source As
System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles DataGrid1.ItemCommand
If e.CommandName = mstrAlphaPageCommand Then
DataGrid1.PageSize = System.Int32.MaxValue
DataGrid1.CurrentPageIndex = 0
Try
BindGrid(e.CommandArgument)
Catch excp As HttpException
DataGrid1.CurrentPageIndex = 0
BindGrid(e.CommandArgument)
End Try
End If
End Sub

Private Function GetPagingRow(ByVal objItem As
DataGridItem) As Table
Dim intColspan As Integer = objItem.Cells.Count
Dim tcNumPageRow As New TableRow()
tcNumPageRow.HorizontalAlign =
DataGrid1.PagerStyle.HorizontalAlign
Dim tcNumPageCell As TableCell
For Each tcNumPageCell In objItem.Cells
tcNumPageRow.Cells.Add(tcNumPageCell)
Next
Dim tcAlphaPageRow As New TableRow()
tcAlphaPageRow.HorizontalAlign =
DataGrid1.PagerStyle.HorizontalAlign
Dim tcAlphaPageCell As New TableCell()
tcAlphaPageCell.ColumnSpan = intColspan
Dim i As Integer
For i = 65 To 65 + 25
If mstrAlphaPageList.IndexOf(Chr(i)) <> -1 Then
Dim l As New LinkButton()
Dim lc As New LiteralControl()
lc.Text = " "
l.Text = Chr(i)
l.CommandName = mstrAlphaPageCommand
l.CommandArgument = Chr(i)
tcAlphaPageCell.Controls.Add(l)
tcAlphaPageCell.Controls.Add(lc)
Else
Dim lbl As New Label()
lbl.Text = Chr(i) & " "
tcAlphaPageCell.Controls.Add(lbl)
End If
Next
tcAlphaPageRow.Cells.Add(tcAlphaPageCell)
Dim tcTable As New Table()
tcTable.Width =
System.Web.UI.WebControls.Unit.Percentage(100)
tcTable.Rows.Add(tcNumPageRow)
tcTable.Rows.Add(tcAlphaPageRow)
Return tcTable
End Function

Private Sub DataGrid1_ItemCreated(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Pager Then
Dim tcPageTable As Table = GetPagingRow(e.Item)
Dim tcPageCell As New TableCell()
tcPageCell.ColumnSpan = DataGrid1.Columns.Count
tcPageCell.Controls.Add(tcPageTable)
e.Item.Cells.Clear()
e.Item.Cells.Add(tcPageCell)
End If
End Sub
End Class
------------------------------------------------
 
A

Alvin Bruney [MVP]

try this instead,
currentpageindex
datasource
databind

can you reproduce this error at will?

If you can, CTRL +ALT + E, choose break into the debugger, ok. Reproduce the
problem. Point me to the line of code which fires the exception.
 
S

Spike

The error occurs only when the dataset returns more than 1
row. It occurs when I bind the grid in the ItemCommand
event i.e.
BindGrid(e.CommandArgument)
-----Original Message-----
try this instead,
currentpageindex
datasource
databind

can you reproduce this error at will?

If you can, CTRL +ALT + E, choose break into the debugger, ok. Reproduce the
problem. Point me to the line of code which fires the exception.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
Here is the WebForm
-------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb"
Inherits="DataGridPageProblem.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio.NET
7.0" name="GENERATOR">
<meta content="Visual Basic 7.0"
name="CODE_LANGUAGE">
<meta content="JavaScript"
name="vs_defaultClientScript">
<meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post"
runat="server">
<asp:DataGrid id="DataGrid1"
runat="server" PageSize="10" Height="0px" Width="100%"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="0">
<SelectedItemStyle Font-
Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle
ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-
Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<Columns>
<ASP:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="Last Name"></ASP:BoundColumn>
<ASP:BoundColumn
DataField="Title" SortExpression="Title"
HeaderText="Title" Visible="False"></ASP:BoundColumn>
<ASP:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="First Name"></ASP:BoundColumn>
</Columns>
<PagerStyle Font-
Bold="True" HorizontalAlign="Right" ForeColor="#330099"
BackColor="#FFFFCC" Mode="NumericPages"></PagerStyle>
</asp:DataGrid><BR>
</form>
</FORM></FORM>
</body>
</HTML>
---------------------------------------
Here is the code behind
----------------------------
Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid

Private Const mstrAlphaPageCommand = "AlphaPage"
Private mstrAlphaPageList As String
= "A,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
Private mConnectionString As String = "Password=;User
ID=sa;Data Source=<<datasource>>;Initial Catalog=Northwind"

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web
Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub

Sub BindGrid(Optional ByVal alpha As String = "")
Dim cnn As New SqlConnection(mConnectionString)
Dim da As SqlDataAdapter
If alpha = "" Then
'da = New SqlDataAdapter("select
title,lastname,firstname from employees where lastname
like 'D%'", cnn)
da = New SqlDataAdapter("select
title,lastname,firstname from employees", cnn)
Else
da = New SqlDataAdapter("select
title,lastname,firstname from employees where lastname
like '" & LCase(alpha) & "%'", cnn)
End If
Dim ds As New DataSet()
da.Fill(ds, "employees")
DataGrid1.DataSource = ds
DataGrid1.CurrentPageIndex = 0
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_SelectedIndexChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles DataGrid1.SelectedIndexChanged

End Sub

Private Sub DataGrid1_PageIndexChanged(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub

Private Sub DataGrid1_ItemCommand(ByVal source As
System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles DataGrid1.ItemCommand
If e.CommandName = mstrAlphaPageCommand Then
DataGrid1.PageSize = System.Int32.MaxValue
DataGrid1.CurrentPageIndex = 0
Try
BindGrid(e.CommandArgument)
Catch excp As HttpException
DataGrid1.CurrentPageIndex = 0
BindGrid(e.CommandArgument)
End Try
End If
End Sub

Private Function GetPagingRow(ByVal objItem As
DataGridItem) As Table
Dim intColspan As Integer = objItem.Cells.Count
Dim tcNumPageRow As New TableRow()
tcNumPageRow.HorizontalAlign =
DataGrid1.PagerStyle.HorizontalAlign
Dim tcNumPageCell As TableCell
For Each tcNumPageCell In objItem.Cells
tcNumPageRow.Cells.Add(tcNumPageCell)
Next
Dim tcAlphaPageRow As New TableRow()
tcAlphaPageRow.HorizontalAlign =
DataGrid1.PagerStyle.HorizontalAlign
Dim tcAlphaPageCell As New TableCell()
tcAlphaPageCell.ColumnSpan = intColspan
Dim i As Integer
For i = 65 To 65 + 25
If mstrAlphaPageList.IndexOf(Chr(i)) <> -1 Then
Dim l As New LinkButton()
Dim lc As New LiteralControl()
lc.Text = " "
l.Text = Chr(i)
l.CommandName = mstrAlphaPageCommand
l.CommandArgument = Chr(i)
tcAlphaPageCell.Controls.Add(l)
tcAlphaPageCell.Controls.Add(lc)
Else
Dim lbl As New Label()
lbl.Text = Chr(i) & " "
tcAlphaPageCell.Controls.Add(lbl)
End If
Next
tcAlphaPageRow.Cells.Add(tcAlphaPageCell)
Dim tcTable As New Table()
tcTable.Width =
System.Web.UI.WebControls.Unit.Percentage(100)
tcTable.Rows.Add(tcNumPageRow)
tcTable.Rows.Add(tcAlphaPageRow)
Return tcTable
End Function

Private Sub DataGrid1_ItemCreated(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Pager Then
Dim tcPageTable As Table = GetPagingRow (e.Item)
Dim tcPageCell As New TableCell()
tcPageCell.ColumnSpan = DataGrid1.Columns.Count
tcPageCell.Controls.Add(tcPageTable)
e.Item.Cells.Clear()
e.Item.Cells.Add(tcPageCell)
End If
End Sub
End Class


.
 
A

Alvin Bruney [MVP]

DataGrid1.PageSize = System.Int32.MaxValue

This is one problem since you are setting the size to be larger than the
collection. If you want to remove paging, set DataGrid1.AllowPaging = false

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
The error occurs only when the dataset returns more than 1
row. It occurs when I bind the grid in the ItemCommand
event i.e.
BindGrid(e.CommandArgument)
-----Original Message-----
try this instead,
currentpageindex
datasource
databind

can you reproduce this error at will?

If you can, CTRL +ALT + E, choose break into the debugger, ok. Reproduce the
problem. Point me to the line of code which fires the exception.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
Here is the WebForm
-------------------------------
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb"
Inherits="DataGridPageProblem.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio.NET
7.0" name="GENERATOR">
<meta content="Visual Basic 7.0"
name="CODE_LANGUAGE">
<meta content="JavaScript"
name="vs_defaultClientScript">
<meta
content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post"
runat="server">
<asp:DataGrid id="DataGrid1"
runat="server" PageSize="10" Height="0px" Width="100%"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CellPadding="0">
<SelectedItemStyle Font-
Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle
ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-
Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<Columns>
<ASP:BoundColumn
DataField="LastName" SortExpression="LastName"
HeaderText="Last Name"></ASP:BoundColumn>
<ASP:BoundColumn
DataField="Title" SortExpression="Title"
HeaderText="Title" Visible="False"></ASP:BoundColumn>
<ASP:BoundColumn
DataField="FirstName" SortExpression="FirstName"
HeaderText="First Name"></ASP:BoundColumn>
</Columns>
<PagerStyle Font-
Bold="True" HorizontalAlign="Right" ForeColor="#330099"
BackColor="#FFFFCC" Mode="NumericPages"></PagerStyle>
</asp:DataGrid><BR>
</form>
</FORM></FORM>
</body>
</HTML>
---------------------------------------
Here is the code behind
----------------------------
Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As
System.Web.UI.WebControls.DataGrid

Private Const mstrAlphaPageCommand = "AlphaPage"
Private mstrAlphaPageList As String
= "A,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
Private mConnectionString As String = "Password=;User
ID=sa;Data Source=<<datasource>>;Initial Catalog=Northwind"

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web
Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
End If
End Sub

Sub BindGrid(Optional ByVal alpha As String = "")
Dim cnn As New SqlConnection(mConnectionString)
Dim da As SqlDataAdapter
If alpha = "" Then
'da = New SqlDataAdapter("select
title,lastname,firstname from employees where lastname
like 'D%'", cnn)
da = New SqlDataAdapter("select
title,lastname,firstname from employees", cnn)
Else
da = New SqlDataAdapter("select
title,lastname,firstname from employees where lastname
like '" & LCase(alpha) & "%'", cnn)
End If
Dim ds As New DataSet()
da.Fill(ds, "employees")
DataGrid1.DataSource = ds
DataGrid1.CurrentPageIndex = 0
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_SelectedIndexChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles DataGrid1.SelectedIndexChanged

End Sub

Private Sub DataGrid1_PageIndexChanged(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEventArgs)
Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub

Private Sub DataGrid1_ItemCommand(ByVal source As
System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Handles DataGrid1.ItemCommand
If e.CommandName = mstrAlphaPageCommand Then
DataGrid1.PageSize = System.Int32.MaxValue
DataGrid1.CurrentPageIndex = 0
Try
BindGrid(e.CommandArgument)
Catch excp As HttpException
DataGrid1.CurrentPageIndex = 0
BindGrid(e.CommandArgument)
End Try
End If
End Sub

Private Function GetPagingRow(ByVal objItem As
DataGridItem) As Table
Dim intColspan As Integer = objItem.Cells.Count
Dim tcNumPageRow As New TableRow()
tcNumPageRow.HorizontalAlign =
DataGrid1.PagerStyle.HorizontalAlign
Dim tcNumPageCell As TableCell
For Each tcNumPageCell In objItem.Cells
tcNumPageRow.Cells.Add(tcNumPageCell)
Next
Dim tcAlphaPageRow As New TableRow()
tcAlphaPageRow.HorizontalAlign =
DataGrid1.PagerStyle.HorizontalAlign
Dim tcAlphaPageCell As New TableCell()
tcAlphaPageCell.ColumnSpan = intColspan
Dim i As Integer
For i = 65 To 65 + 25
If mstrAlphaPageList.IndexOf(Chr(i)) <> -1 Then
Dim l As New LinkButton()
Dim lc As New LiteralControl()
lc.Text = " "
l.Text = Chr(i)
l.CommandName = mstrAlphaPageCommand
l.CommandArgument = Chr(i)
tcAlphaPageCell.Controls.Add(l)
tcAlphaPageCell.Controls.Add(lc)
Else
Dim lbl As New Label()
lbl.Text = Chr(i) & " "
tcAlphaPageCell.Controls.Add(lbl)
End If
Next
tcAlphaPageRow.Cells.Add(tcAlphaPageCell)
Dim tcTable As New Table()
tcTable.Width =
System.Web.UI.WebControls.Unit.Percentage(100)
tcTable.Rows.Add(tcNumPageRow)
tcTable.Rows.Add(tcAlphaPageRow)
Return tcTable
End Function

Private Sub DataGrid1_ItemCreated(ByVal sender As
Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Pager Then
Dim tcPageTable As Table = GetPagingRow (e.Item)
Dim tcPageCell As New TableCell()
tcPageCell.ColumnSpan = DataGrid1.Columns.Count
tcPageCell.Controls.Add(tcPageTable)
e.Item.Cells.Clear()
e.Item.Cells.Add(tcPageCell)
End If
End Sub
End Class


.
 
S

Spike

Yes that is the problem. But it fails only if I set
Pagesize to System.Int32.MaxValue. I tried setting
Pagesize to 10000000 and it worked fine. Seems strange
that Pagesize cannot be set to max integer value.
 
A

Alvin Bruney [MVP]

would you mind reporting this as a bug? here's a link.
http://support.microsoft.com/default.aspx?scid=fh;[ln];oasoem

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
Yes that is the problem. But it fails only if I set
Pagesize to System.Int32.MaxValue. I tried setting
Pagesize to 10000000 and it worked fine. Seems strange
that Pagesize cannot be set to max integer value.
-----Original Message-----
DataGrid1.PageSize = System.Int32.MaxValue

This is one problem since you are setting the size to be larger than the
collection. If you want to remove paging, set DataGrid1.AllowPaging = false

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
 
A

Alvin Bruney [MVP]

write up a complete report and post it here. I'll route it to product
support. Sorry, I should have offered you this option in the first place.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
Which option do I select on the support web-site to report
bugs? My product purchase does not include online assisted
support and I cant see any other option to report bugs.
-----Original Message-----
would you mind reporting this as a bug? here's a link.
http://support.microsoft.com/default.aspx?scid=fh; [ln];oasoem

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
Yes that is the problem. But it fails only if I set
Pagesize to System.Int32.MaxValue. I tried setting
Pagesize to 10000000 and it worked fine. Seems strange
that Pagesize cannot be set to max integer value.
-----Original Message-----
DataGrid1.PageSize = System.Int32.MaxValue

This is one problem since you are setting the size to be
larger than the
collection. If you want to remove paging, set
DataGrid1.AllowPaging = false

--
Regards,
Alvin Bruney
[ASP.NET MVP
http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok


.
 
S

Spike

Well here's the report.
-----------------------------
Setting PageSize property of DataGrid to
System.Integer.MaxValue gives the following error

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

Steps to reproduce the error
1. Create a new ASP.Net Web project.
2. Add a WebForm to the project.
3. Add a DataGird (DataGrid1) to the WebForm.
4. Enable Paging for the datagrid.
5. Add atleast 1 ButtonColumn to the DataGrid
6. Write code to bind the DataGrid to any datasource.
7. Trap the ItemCommand Event for the Button Column.
8. In the ItemCommand event add the following code
DataGrid1.Pagesize = System.Int32.MaxValue.
9. Run the application.
10. Clicking on the ButtonColumn should give the error.
 
S

Spike

Oops I seem to have missed out some important info in the
report. Heres the updated report
-----------------------------
Setting PageSize property of DataGrid to
System.Integer.MaxValue gives the following error

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

Steps to reproduce the error
1. Create a new ASP.Net Web project.
2. Add a WebForm to the project.
3. Add a DataGird (DataGrid1) to the WebForm.
4. Enable Paging for the datagrid.
5. Add atleast 1 ButtonColumn to the DataGrid
6. Write code to bind the DataGrid to any datasource.
7. Trap the ItemCommand Event for the Button Column.
8. In the ItemCommand event add the following code
DataGrid1.Pagesize = System.Int32.MaxValue.
Code to bind the datagrid to datasource.
9. Run the application.
10. Clicking on the ButtonColumn should give the error.
---------------------------------------------
-----Original Message-----
Well here's the report.
-----------------------------
Setting PageSize property of DataGrid to
System.Integer.MaxValue gives the following error

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

Steps to reproduce the error
1. Create a new ASP.Net Web project.
2. Add a WebForm to the project.
3. Add a DataGird (DataGrid1) to the WebForm.
4. Enable Paging for the datagrid.
5. Add atleast 1 ButtonColumn to the DataGrid
6. Write code to bind the DataGrid to any datasource.
7. Trap the ItemCommand Event for the Button Column.
8. In the ItemCommand event add the following code
DataGrid1.Pagesize = System.Int32.MaxValue.
9. Run the application.
10. Clicking on the ButtonColumn should give the error.
---------------------------------------------
Hope this would suffice
-----Original Message-----
write up a complete report and post it here. I'll route it to product
support. Sorry, I should have offered you this option in the first place.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok

.
 
A

Alvin Bruney [MVP]

thanks, i'll test and submit.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Spike said:
Oops I seem to have missed out some important info in the
report. Heres the updated report
-----------------------------
Setting PageSize property of DataGrid to
System.Integer.MaxValue gives the following error

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

Steps to reproduce the error
1. Create a new ASP.Net Web project.
2. Add a WebForm to the project.
3. Add a DataGird (DataGrid1) to the WebForm.
4. Enable Paging for the datagrid.
5. Add atleast 1 ButtonColumn to the DataGrid
6. Write code to bind the DataGrid to any datasource.
7. Trap the ItemCommand Event for the Button Column.
8. In the ItemCommand event add the following code
DataGrid1.Pagesize = System.Int32.MaxValue.
Code to bind the datagrid to datasource.
9. Run the application.
10. Clicking on the ButtonColumn should give the error.
---------------------------------------------
-----Original Message-----
Well here's the report.
-----------------------------
Setting PageSize property of DataGrid to
System.Integer.MaxValue gives the following error

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

Steps to reproduce the error
1. Create a new ASP.Net Web project.
2. Add a WebForm to the project.
3. Add a DataGird (DataGrid1) to the WebForm.
4. Enable Paging for the datagrid.
5. Add atleast 1 ButtonColumn to the DataGrid
6. Write code to bind the DataGrid to any datasource.
7. Trap the ItemCommand Event for the Button Column.
8. In the ItemCommand event add the following code
DataGrid1.Pagesize = System.Int32.MaxValue.
9. Run the application.
10. Clicking on the ButtonColumn should give the error.
---------------------------------------------
Hope this would suffice
-----Original Message-----
write up a complete report and post it here. I'll route it to product
support. Sorry, I should have offered you this option in the first place.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top