Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Oliver Hopton #1
Collection class bound to DataGrid doesn't use my custom enumerator!
Hello,
I'm trying to implement a PageableCollection class so I can easily add
custom paging functionality to my apps without the overhead of using the
DataGrid's paging functionality and the huge ViewState that generates. What
I have done works fine when I use foreach to iterate over my collection but
when I bind it to a DataGrid the DataGrid doesn't appear to use my
Enumerator, I'm guessing that it uses the base classes Enumerator or perhaps
it access the contents of the collection in a different way?
Anybody got any idea what is going on here and why?
Thanks,
Oliver.
Code follows:
public class PageableCollection : CollectionBase, IEnumerable
{
private bool fAllowPaging;
private int fPageSize;
private int fCurrentPage;
internal object this[int index]
{
get { return List[index]; }
set { List[index] = value; }
}
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
{
int retval = Count / fPageSize;
if (Count != fPageSize)
retval++;
return retval;
}
}
public PageableCollection()
{
fAllowPaging = false;
fPageSize = 10;
fCurrentPage = 1;
}
public new IEnumerator GetEnumerator()
{
return new PageableCollectionEnumerator(this);
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
internal class PageableCollectionEnumerator: IEnumerator
{
private int fIndex;
private PageableCollection CollectionToEnumerate;
public PageableCollectionEnumerator(PageableCollection
CollectionToEnumerate)
{
this.CollectionToEnumerate = CollectionToEnumerate;
Reset();
}
public void Reset()
{
if (CollectionToEnumerate.AllowPaging)
fIndex = (CollectionToEnumerate.PageSize *
CollectionToEnumerate.CurrentPage) - CollectionToEnumerate.PageSize;
else
fIndex = 0;
fIndex--;
}
public object Current
{
get
{
return CollectionToEnumerate[fIndex];
}
}
public bool MoveNext()
{
fIndex++;
if (fIndex >= CollectionToEnumerate.Count)
return false;
if (CollectionToEnumerate.AllowPaging)
//If paging is on check to see whether the index is less than the last index
for this page.
return (fIndex < (CollectionToEnumerate.PageSize *
CollectionToEnumerate.CurrentPage));
else
return true;
}
}
Oliver Hopton Guest
-
Collection property "could not be initialized" in design mode for custom datagrid control
Hello all, I've been working on a custom datagrid (custom web control inherited from DataGrid). I am attempting to add a new collection property... -
Persisting a collection property in a custom datagrid
I have a custom control that inherits from a DataGrid control. I have a property that has an arraylist of strings. I want to add items as a child... -
Update Custom Collection that is bound to DataGrid made up of Custom COlumns
I recieved some very useful help from Steven Cheng in an earlier post in this group entitled 'Dynamically create datagrid columns' and am now... -
UserControl inside of datagrid - loses its viewstate when datagrid is re-bound on postback
I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of... -
GetEnumerator from custom collection implementing IList is not invokedon datagrid databind
(I posted this earlier in the databind newsgroup with no reaction, i'll try my luck here :) ) Hi, I've created a custom collection... -
Alan Green #2
Re: Collection class bound to DataGrid doesn't use my custom enumerator!
I've tried this in VB, and the Windows DataGrid appears to merely count
its way up the list rather than use the enumerator. Therefore it can be
tracked using the collection Item property, and could possibly be paged
using the Count and Item properties. However the Web DataGrid doesn't
seem to touch any of my collection class code.
Can anyone shed any light on this?
*** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
Don't just participate in USENET...get rewarded for it!
Alan Green Guest



Reply With Quote

