473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Datagrid PageCount Nightmare!!

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
4 3030
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eric Caron | last post by:
Hi, In a typical "show-list-click-one-and-edit" scenario, I use a DataGrid on the "list" page using the pager option. Say I'm on page 2, click edit on an item and click Cancel on the edit page...
0
by: anon | last post by:
Hi All, tried implementing the custom paging solution from 4 guys from rolla...however the pagecount in my implementation always returns one, so the postback gives an error asying"CurrentPageIndex...
1
by: Bob Morvay | last post by:
This should be simple but I am stuck. I am trying to read all the rows of my datagrid across all the pages. I can read all the rows on the page that I am on but I can't seem to figure out how to...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
3
by: Franck | last post by:
Hello, in a datagrid, in the ItemDataBound event in some cells a add some javascript that show up an information strHref.Append("<A onclick=\"popupValid();\">"); strHref.Append("<span...
0
by: Jim Mirra | last post by:
Hey, I have been working on this for a while now and I keep getting the same error. here is my code: ------- start code --------- Dim strSQL = "Select tagid,itemid,description,status,...
6
by: Jim Mirra | last post by:
Hey, I have been working on this for a while now and I keep getting the same error. here is my code: ------- start code --------- Dim strSQL = "Select tagid,itemid,description,status,...
10
by: Doug Bell | last post by:
Hi I am still having problems with Tabbing through a DataGrid with a DataGridComboBox Column. I need to allow the User to Type the value into the ComboBox so consequently its ComboBoxStyle is...
2
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all Got a weird problem with pagination on a datagrid in asp.net 1.1. It's populated depending on user selected criteria (it either displays all or 1 record). It works fine in the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.