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

N

nxliu

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!
 
B

Ben Lovell

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.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top