The data source does not support server-side data paging

I have a GridView on my screen and need it to allow paging.


<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
  AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
    <asp:BoundField DataField="appID" HeaderText="appID" SortExpression="appID" />

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    <asp:Parameter Name="maximumRows" Type="Int32" />
    <asp:Parameter Name="startRowIndex" Type="Int32" />


ObjectDataSource1.SelectParameters["maximumRows"].DefaultValue = "10";
ObjectDataSource1.SelectParameters["startRowIndex"].DefaultValue = "0";

LINQ query:

public IQueryable<tblAppointment> GetBookingId(int maximumRows, int startRowIndex)
    var result = (FROM a IN dc.tblAppointments
                  SELECT a).Skip(startRowIndex).Take(maximumRows);

However I receive this error:

The data source does not support server-side data paging.

What am I doing wrong?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

A simple ToList() on your result var should work.

As explained in comments below my answer, the reason for the error is that the data source should implement ICollection. IEnumerable does not, when you do ToList() it converts it into a list which implements ICollection.

Method 2

You can use generic List<T> also. See the sample code snippet:

public List<Company> GetContactList(int startindex)

    string path = Server.MapPath("~/contacts.xml");
    XDocument xd = XDocument.Load(path);
    IEnumerable<Company> results = (from items in xd.Elements("Company").Elements("Contact")
                   select new Company
                       Id = items.Element("ID").Value,
                       Photo = (string)items.Element("photo").Value,
                       Name = (string)items.Element("Name").Value,
                       BloodGroup = (string)items.Element("Bg").Value,
                       Dob = (string)items.Element("dob").Value,
                       Anniversery = (string)items.Element("avd").Value,
                       Mobile = (string)items.Element("cnum").Value,
                       designation = (string)items.Element("desig").Value,
                       Team = (string)items.Element("team").Value
    return (List<Company>) results;

You can also use DataSet/DataTable instead of DataReader.

Method 3

.ToList() at the end of the DataSource, I am assigning worked for me like below:

gvCaseLabelsLeft.DataSource = caseLabelsList.OrderBy(c=>c.caseLabelNumber).ToList();

Method 4

I’ve changed my code to this:

public List<string> ListofNewsTitle()
    var query = from n in db.NewsEvents
                orderby n.NewsDate descending
                select n.NewsTitle;
    return query.ToList();        

Method 5

In ObjectDataSource just add enablePaging="true" that will work.

Method 6

LINQ query:


List<Product> products= productModel.GetProducts(start, offset);


public List<Product> GetProducts(int start, int offset)
    IEnumerable<Product> query = from m in db.Products
                                 orderby m.Id descending
                                 select m;
    query = query.Skip(start).Take(offset);
    return query.ToList();

Method 7

If You are Using SqldataReader then its not support Paging.

Solution to this error is making use of DataSources such as Generic List collections, DataTables, DataSets, etc. to bind the GridView.

Method 8

Try this article

in summary try to use these lines

private void BindGrid()
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
        using (SqlCommand cmd = new SqlCommand("SELECT CustomerId, ContactName, Country FROM Customers"))
            cmd.Connection = con;
            using (SqlDataReader sdr = cmd.ExecuteReader())
                GridView1.DataSource = sdr;

protected void OnPaging(object sender, GridViewPageEventArgs e)
    GridView1.PageIndex = e.NewPageIndex;

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true"
    <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" />
    <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
    <asp:BoundField DataField="Country" HeaderText="Country" />

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x