SqlDataReader and GridView with pages?

Posted on 2007-10-08
Last Modified: 2013-11-07
How i can use SqlDataReader binded to GridView to be paged, i have used pageing when i return DataTable and bind it to GridView it runs okay, but when i return SqlDataReader it does not run, it show me an error: this error bellow:
System.Web.HttpException: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID 'DataGrid1' when AllowPaging is set to true and the selected data source does not implement ICollection. at System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) at System.Web.UI.WebControls.BaseDataList.DataBind()
Question by:baghlaf
    LVL 9

    Expert Comment

    A sqldatareader is a forward only cursor.

    You need to use a dataset iirc
    LVL 7

    Expert Comment

    by:Abu Hamdan
    As i know you cant use Datareader along with paging in datagrid,, since it works as connected to db ,, not like dataset, datatable ,,

    see this,
    LVL 9

    Accepted Solution

    If you really wanted to you can write in your own paging for datareader but i don't really see the point?

    Author Comment

    if i write my own paging for datareader, so i cannot benifit from ASP.NET AJAX, i mean the page whole page will post back not using ajax... can you tell me how i can write custom paging for datareader so i can use ajax with it..??

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now