Collection class bound to DataGrid doesn't use my custom enumerator!

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139