DataGrid Issue: "Cannot compute Count" for AllowCustomPaging

S

Steve Litvack

Hello:

I am using the techniques mentioned elsewhere for using the DataGrid's
custom-paging ability. I have a query that returns only the specific range
of records I request (this range applies, of course, to the current page
being viewed by the user). I want to use a SqlDataReader instead of a
DataSet because I have no need to update the data and SqlDataReader is
purportedly much faster.

When I add a DataGrid to the aspx document, set its AllowCustomPaging to
true, then set its VirtualItemCount to 20 (in Page_Load), then set its
DataSource to my SqlDataReader, then do a DataBind() call, I get this error
message:

--> "Cannot compute Count for a data source that does not implement
ICollection"

I was under the impression that a Count is not attempted by the DataGrid
control when AllowCustomPaging is true--but this apparently is not what I'm
seeing.

I even verified in the debugger that AllowCustomPaging and VirtualItemCount
properties were true and 20, respectively, immediate before the call to
DataBind().

I would be greatful for any help.

-- Steve
 
M

Michael Tkachev

Hello,

DataSourse of datagrid must use classes that were inheritance from interface
ICollection.
Interface ICollection has property Count. And SqlDataReader does not have
this property. Therefore you can not use SqlDataReader.


Web Developer
Michael Tkachev
 
S

Steve Litvack

So do people who want to use a SqlDataReader first read results into a, say,
ArrayList or DataTable in the code-behind and then attach that
ArrayList/DataTable object to the grid's datasource? Are there other
techniques I should know about?

Thanks,
Steve
 
S

Steve Litvack

Apparently, you CAN set a datagrid's DataSource to a DataReader--but you
must set AllowCustomPaging to true. Scott Mitchell writes about this
technique in his fine article:
http://www.informit.com/isapi/product_id~{0CB2E00E-6408-440C-A853-33D5358A78AF}/content/index.asp

Although I seem to be following the correct implementation, I am still not
sure why I am getting the error I see. I am convinced, however, that the
DataGrid can take a DataReader as its DataSource (there are dozens of
articles that describe how this is done).

Steve
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top