By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,041 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Datagrid PageCount Nightmare!!

P: n/a
Hello All,

I am having a nightmare trying to add a new row to my
Datagrid. When I use the code below I get the
error: 'Invalid CurrentPageIndex value. It must be >= 0
and < the PageCount. Can anyone help me with this?

Dim dg2 as DataGrid = DG.Items(0).FindControl("dg2")
DSClass = Session("DSClass")
dt = DSClass.Tables(0)
dim dr as DataRow = dt.NewRow ()
dt.Rows.Add(dr)
Session("DSClass") = DSClass
dg2.DataSource = Session("DSClass")

intIndex = dg2.Items.Count ''intIndex = 7

If intIndex >= dg2.PageSize Then ''Page Size = 7

''At present CurrentPageIndex = 0

dg2.CurrentPageIndex = dg2.CurrentPageIndex + 1
intIndex = 0

''CurrentPageIndex = 1 And PageCount = 1

End if

dg2.EditItemIndex = intIndex

dg2.Datasource = Session("DSClass").Tables(0)
dg2.DataBind()
''Errors here because CurrentPageIndex = 1 and needs to be
less than 1, but this is not the page I want to be
displayed?

Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try setting the CurrentPageIndex to zero before you add the new row.

I encountered the "'Invalid CurrentPageIndex value. It must be >= 0 > and <
the PageCount" in the following scenario.

I bind my DataGrid to my DataSet and go to Page 2. Let's say I rebind to a
new DataSet which would only contain on Page of records, but the DataGrid is
still at Page 2. I'd get the above error.

So before I rebind, I always set the CurrentPageIndex to 0

"Dave" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Hello All,

I am having a nightmare trying to add a new row to my
Datagrid. When I use the code below I get the
error: 'Invalid CurrentPageIndex value. It must be >= 0
and < the PageCount. Can anyone help me with this?

Dim dg2 as DataGrid = DG.Items(0).FindControl("dg2")
DSClass = Session("DSClass")
dt = DSClass.Tables(0)
dim dr as DataRow = dt.NewRow ()
dt.Rows.Add(dr)
Session("DSClass") = DSClass
dg2.DataSource = Session("DSClass")

intIndex = dg2.Items.Count ''intIndex = 7

If intIndex >= dg2.PageSize Then ''Page Size = 7

''At present CurrentPageIndex = 0

dg2.CurrentPageIndex = dg2.CurrentPageIndex + 1
intIndex = 0

''CurrentPageIndex = 1 And PageCount = 1

End if

dg2.EditItemIndex = intIndex

dg2.Datasource = Session("DSClass").Tables(0)
dg2.DataBind()
''Errors here because CurrentPageIndex = 1 and needs to be
less than 1, but this is not the page I want to be
displayed?

Nov 17 '05 #2

P: n/a
Hi,
Thanks for replying,

I see what you're saying here but when I do this I end up
not editing the row I need,
I need to be editing the first record of the last page,
when I set the current page index to 0 I end up editing
the first record of the first page?

-----Original Message-----
Try setting the CurrentPageIndex to zero before you add the new row.
I encountered the "'Invalid CurrentPageIndex value. It must be >= 0 > and <the PageCount" in the following scenario.

I bind my DataGrid to my DataSet and go to Page 2. Let's say I rebind to anew DataSet which would only contain on Page of records, but the DataGrid isstill at Page 2. I'd get the above error.

So before I rebind, I always set the CurrentPageIndex to 0

"Dave" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...
Hello All,

I am having a nightmare trying to add a new row to my
Datagrid. When I use the code below I get the
error: 'Invalid CurrentPageIndex value. It must be >= 0
and < the PageCount. Can anyone help me with this?

Dim dg2 as DataGrid = DG.Items(0).FindControl("dg2")
DSClass = Session("DSClass")
dt = DSClass.Tables(0)
dim dr as DataRow = dt.NewRow ()
dt.Rows.Add(dr)
Session("DSClass") = DSClass
dg2.DataSource = Session("DSClass")

intIndex = dg2.Items.Count ''intIndex = 7

If intIndex >= dg2.PageSize Then ''Page Size = 7

''At present CurrentPageIndex = 0

dg2.CurrentPageIndex = dg2.CurrentPageIndex + 1
intIndex = 0

''CurrentPageIndex = 1 And PageCount = 1

End if

dg2.EditItemIndex = intIndex

dg2.Datasource = Session("DSClass").Tables(0)
dg2.DataBind()
''Errors here because CurrentPageIndex = 1 and needs to be less than 1, but this is not the page I want to be
displayed?

.

Nov 17 '05 #3

P: n/a
So you want to add a new record to the DataGrid, and immediately edit it?
Check out this MSDN article section: The Insert Operation
http://msdn.microsoft.com/library/de...asp?frame=true

"Dave" <an*******@discussions.microsoft.com> wrote in message
news:33****************************@phx.gbl...
Hi,
Thanks for replying,

I see what you're saying here but when I do this I end up
not editing the row I need,
I need to be editing the first record of the last page,
when I set the current page index to 0 I end up editing
the first record of the first page?

-----Original Message-----
Try setting the CurrentPageIndex to zero before you add

the new row.

I encountered the "'Invalid CurrentPageIndex value. It

must be >= 0 > and <
the PageCount" in the following scenario.

I bind my DataGrid to my DataSet and go to Page 2. Let's

say I rebind to a
new DataSet which would only contain on Page of records,

but the DataGrid is
still at Page 2. I'd get the above error.

So before I rebind, I always set the CurrentPageIndex to 0

"Dave" <an*******@discussions.microsoft.com> wrote in

message
news:07****************************@phx.gbl...
Hello All,

I am having a nightmare trying to add a new row to my
Datagrid. When I use the code below I get the
error: 'Invalid CurrentPageIndex value. It must be >= 0
and < the PageCount. Can anyone help me with this?

Dim dg2 as DataGrid = DG.Items(0).FindControl("dg2")
DSClass = Session("DSClass")
dt = DSClass.Tables(0)
dim dr as DataRow = dt.NewRow ()
dt.Rows.Add(dr)
Session("DSClass") = DSClass
dg2.DataSource = Session("DSClass")

intIndex = dg2.Items.Count ''intIndex = 7

If intIndex >= dg2.PageSize Then ''Page Size = 7

''At present CurrentPageIndex = 0

dg2.CurrentPageIndex = dg2.CurrentPageIndex + 1
intIndex = 0

''CurrentPageIndex = 1 And PageCount = 1

End if

dg2.EditItemIndex = intIndex

dg2.Datasource = Session("DSClass").Tables(0)
dg2.DataBind()
''Errors here because CurrentPageIndex = 1 and needs to be less than 1, but this is not the page I want to be
displayed?

.

Nov 17 '05 #4

P: n/a
Thanks!

-----Original Message-----
So you want to add a new record to the DataGrid, and immediately edit it?Check out this MSDN article section: The Insert Operation
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndive/html/Data02142002.asp?frame=true
"Dave" <an*******@discussions.microsoft.com> wrote in messagenews:33****************************@phx.gbl...
Hi,
Thanks for replying,

I see what you're saying here but when I do this I end up
not editing the row I need,
I need to be editing the first record of the last page,
when I set the current page index to 0 I end up editing
the first record of the first page?

>-----Original Message-----
>Try setting the CurrentPageIndex to zero before you add

the new row.
>
>I encountered the "'Invalid CurrentPageIndex value. It

must be >= 0 > and <
>the PageCount" in the following scenario.
>
>I bind my DataGrid to my DataSet and go to Page 2. Let's
say I rebind to a
>new DataSet which would only contain on Page of
records, but the DataGrid is
>still at Page 2. I'd get the above error.
>
>So before I rebind, I always set the CurrentPageIndex
to 0 >
>"Dave" <an*******@discussions.microsoft.com> wrote in

message
>news:07****************************@phx.gbl...
>> Hello All,
>>
>> I am having a nightmare trying to add a new row to my
>> Datagrid. When I use the code below I get the
>> error: 'Invalid CurrentPageIndex value. It must be

= 0 >> and < the PageCount. Can anyone help me with this?
>>
>> Dim dg2 as DataGrid = DG.Items(0).FindControl("dg2")
>> DSClass = Session("DSClass")
>> dt = DSClass.Tables(0)
>> dim dr as DataRow = dt.NewRow ()
>> dt.Rows.Add(dr)
>> Session("DSClass") = DSClass
>> dg2.DataSource = Session("DSClass")
>>
>> intIndex = dg2.Items.Count ''intIndex = 7
>>
>> If intIndex >= dg2.PageSize Then ''Page Size = 7
>>
>> ''At present CurrentPageIndex = 0
>>
>> dg2.CurrentPageIndex = dg2.CurrentPageIndex + 1
>> intIndex = 0
>>
>> ''CurrentPageIndex = 1 And PageCount = 1
>>
>> End if
>>
>> dg2.EditItemIndex = intIndex
>>
>> dg2.Datasource = Session("DSClass").Tables(0)
>> dg2.DataBind()
>> ''Errors here because CurrentPageIndex = 1 and needs

to be
>> less than 1, but this is not the page I want to be
>> displayed?
>>
>
>
>.
>

.

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.