470,573 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,573 developers. It's quick & easy.

Datagrid bound to CollectionBase class doesn't use Enumerator!

Hello,

I'm trying to write a PageableCollection class which implements paging for
me so I don't need to rely on the paging provided by the DataGrid as that
generates huge viewstate when bound to a collection with a lot of items.

The code below works fine when I use foreach to iterate over it but when I
bind the Datagrid to an instance of this class I get the whole collection
displayed in the grid! Does the Datagrid not use GetEnumerator to obtain an
enumerator? I've also tried overriding the indexer and count properties of
the collection with no success.

Is the DataGrid doing something cheesy with Reflection in the case of being
bound to a class derived from CollectionBase to get directly at the
InnerList inside the collection?

Anybody got any idea what is going on here?

Thanks.
Code follows:

public class PageableCollection : CollectionBase
{
private bool fAllowPaging;
private int fPageSize;
private int fCurrentPage;

public int CurrentPage
{
get { return fCurrentPage; }
set { fCurrentPage = value; }
}

public bool AllowPaging
{
get { return fAllowPaging; }
set { fAllowPaging = value; }
}

public int PageSize
{
get { return fPageSize; }
set { fPageSize = value; }
}

public int PageCount
{
get
{
return ((Count % fPageSize) == 0) ? (Count / fPageSize) : ((Count /
fPageSize) + 1);
}
}

public PageableCollection()
{
fAllowPaging = false;
fPageSize = 20;
fCurrentPage = 1;
}

public new IEnumerator GetEnumerator()
{
if (!fAllowPaging)
return base.GetEnumerator();
else
{
int index = ((fPageSize * fCurrentPage) - fPageSize);
int count = fPageSize;

if ((count + index) > Count)
count = Count - index;

return InnerList.GetEnumerator(index, count);
}
}
Nov 15 '05 #1
0 1209

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matthew Fitzpatrick | last post: by
reply views Thread by Shannon Richards | last post: by
6 posts views Thread by GingerNinja | last post: by
7 posts views Thread by Pete Davis | last post: by
1 post views Thread by Angelos Karantzalis | last post: by
1 post views Thread by Matthew Roberts | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.