Cannot compute Count for a data source that does not implement ICollection.

Discussion in 'ASP .Net Web Controls' started by nxliu, Aug 25, 2004.

  1. nxliu

    nxliu Guest

    I have some code like:

    XmlNodeList locationNode = xmlDocument.SelectNodes("xpath string");

    PagedDataSource pg = new PagedDataSource();
    pg.DataSource = locationNode;
    pg.AllowPaging = true;
    pg.PageSize = 10;
    pg.CurrentPageIndex = 0;
    DataList1.DataSource = pg;
    DataList1.DataBind();

    when I run the program, it throws exception on line DataList1.DataBind():

    Exception Details: System.Web.HttpException: Cannot compute Count for a data
    source that does not implement ICollection.

    Source Error:

    Line 114: pg.CurrentPageIndex = 0;
    Line 115: DataList1.DataSource = pg;
    Line 116: DataList1.DataBind();
    Line 117: }
    Line 118:


    since the XmlNodeList implements IEnumerable, I really can't find where the
    problem is.
    please help? Thanks in advance!
    nxliu, Aug 25, 2004
    #1
    1. Advertising

  2. nxliu

    Ben Lovell Guest

    Hi,

    The error message in this case is fairly self-explanatory! The XmlNodeList
    type does in fact support IEnumerable but not the required ICollection
    interface. Internally the PagedDataSource type attempts to use the Count
    property exposed on the ICollection interface, if it cannot resolve the page
    count it throws the exception you are getting.

    --
    Ben
    http://bitarray.co.uk/ben



    "nxliu" <> wrote in message
    news:u$...
    >I have some code like:
    >
    > XmlNodeList locationNode = xmlDocument.SelectNodes("xpath string");
    >
    > PagedDataSource pg = new PagedDataSource();
    > pg.DataSource = locationNode;
    > pg.AllowPaging = true;
    > pg.PageSize = 10;
    > pg.CurrentPageIndex = 0;
    > DataList1.DataSource = pg;
    > DataList1.DataBind();
    >
    > when I run the program, it throws exception on line DataList1.DataBind():
    >
    > Exception Details: System.Web.HttpException: Cannot compute Count for a
    > data
    > source that does not implement ICollection.
    >
    > Source Error:
    >
    > Line 114: pg.CurrentPageIndex = 0;
    > Line 115: DataList1.DataSource = pg;
    > Line 116: DataList1.DataBind();
    > Line 117: }
    > Line 118:
    >
    >
    > since the XmlNodeList implements IEnumerable, I really can't find where
    > the
    > problem is.
    > please help? Thanks in advance!
    >
    >
    Ben Lovell, Aug 25, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Janus Knudsen

    method type ICollection returns Dataview

    Janus Knudsen, Jul 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,827
    Natty Gur
    Jul 6, 2004
  2. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    System.Web.HttpException: Cannot compute Count for a data source t

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Nov 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    5,565
    Scott Allen
    Nov 5, 2004
  3. Pinkesh
    Replies:
    0
    Views:
    325
    Pinkesh
    Jan 12, 2007
  4. Steve Litvack

    DataGrid Issue: "Cannot compute Count" for AllowCustomPaging

    Steve Litvack, Aug 12, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    162
    Steve Litvack
    Aug 16, 2003
  5. PerlFAQ Server
    Replies:
    0
    Views:
    256
    PerlFAQ Server
    Feb 2, 2011
Loading...

Share This Page