Paging problem index out of range

M

Maverick

Hello
I'm trying to make a datagrid with paging the datasource is a simpel arraylist with 5 elements. When the page is loaded i
see the first item (pagesize = 1) but when I click next i get at index out of range exception
The OnpageIndexChange code
private void pageChange(Object sender, DataGridPageChangedEventArgs e

reports.CurrentPageIndex = e.NewPageIndex
loadReports()


private void loadReports(

ArrayList a = new ArrayList(5)
a.Add("test 1")
a.Add("test 2")
a.Add("test 3")
a.Add("test 4")
reports.DataSource = a
reports.DataBind()


Can anyone help? Please!!!
 
A

Alessandro Zifiglio

As elements are added to an ArrayList, the capacity is automatically
increased as required through reallocation. I could easily be wrong as i'm
not testing this but at first look i see you have created an arraylist of 5
elements and are actually loading in 4 elements but the count really starts
from zero which cuts the count to actually 3, zero being your first element
and so on.

ArrayList a = new ArrayList(3);
or
just
ArrayList a = new ArrayList();

Maverick said:
Hello,
I'm trying to make a datagrid with paging the datasource is a simpel
arraylist with 5 elements. When the page is loaded i
 
A

Alessandro Zifiglio

dont think its the arraylist, however still, i cant figure why this is not
working for you. All code in your OnpageIndexChange method is correct ;P
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top