Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Invalid CurrentPageIndex error

Reply
Thread Tools

Invalid CurrentPageIndex error

 
 
Spike
Guest
Posts: n/a
 
      05-03-2004
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.
 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      05-03-2004
see this article
http://support.microsoft.com/default...b;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" <(E-Mail Removed)> wrote in message
news:783701c43121$c74a17a0$(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
 
Spike
Guest
Posts: n/a
 
      05-03-2004
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" <(E-Mail Removed)> wrote in message
>news:783701c43121$c74a17a0$(E-Mail Removed)...
>> 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.

>
>
>.
>

 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      05-03-2004
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" <(E-Mail Removed)> wrote in message
news:78cb01c4312a$9766a310$(E-Mail Removed)...
>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" <(E-Mail Removed)> wrote in message
>>news:783701c43121$c74a17a0$(E-Mail Removed)...
>>> 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.

>>
>>
>>.
>>



 
Reply With Quote
 
Spike
Guest
Posts: n/a
 
      05-03-2004
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">
<aspataGrid 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>
</aspataGrid><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.DataGridPageChangedEvent Args)
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
------------------------------------------------

 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      05-03-2004
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" <(E-Mail Removed)> wrote in message
news:7ac501c43137$d82740f0$(E-Mail Removed)...
> 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">
> <aspataGrid 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>
> </aspataGrid><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.DataGridPageChangedEvent Args)
> 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
> ------------------------------------------------
>



 
Reply With Quote
 
Spike
Guest
Posts: n/a
 
      05-04-2004
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" <(E-Mail Removed)> wrote in message
>news:7ac501c43137$d82740f0$(E-Mail Removed)...
>> 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">
>> <aspataGrid 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>
>> </aspataGrid><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.DataGridPageChangedEvent Args)
>> 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
>> ------------------------------------------------
>>

>
>
>.
>

 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      05-04-2004
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" <(E-Mail Removed)> wrote in message
news:7e6801c431b7$4d750f70$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>>news:7ac501c43137$d82740f0$(E-Mail Removed)...
>>> 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">
>>> <aspataGrid 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>
>>> </aspataGrid><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.DataGridPageChangedEvent Args)
>>> 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
>>> ------------------------------------------------
>>>

>>
>>
>>.
>>



 
Reply With Quote
 
Spike
Guest
Posts: n/a
 
      05-05-2004
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


 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      05-05-2004
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" <(E-Mail Removed)> wrote in message
news:891b01c43284$99dd1010$(E-Mail Removed)...
> 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

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. Franck ASP .Net 4 06-29-2007 04:22 AM
Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. George Smith ASP .Net 2 04-27-2007 12:05 AM
Invalid currentPageIndex error message =?Utf-8?B?U2FuZHk=?= ASP .Net 2 04-18-2005 01:31 PM
CurrentPageIndex invalid after a row deleted from datagrid CW ASP .Net 1 04-01-2004 06:13 AM
Invalid CurrentPageIndex value jm ASP .Net 0 10-30-2003 10:42 PM



Advertisments