The data source does not support server-side data paging

62,719

Solution 1

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

Edit: 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.

Solution 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
                   }).Skip(startindex*10).Take(10);
    return (List<Company>) results;
}

You can also use DataSet/DataTable instead of DataReader.

Solution 3

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

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

Solution 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();        
}
Share:
62,719
ClareBear
Author by

ClareBear

:-)

Updated on September 26, 2020

Comments

  • ClareBear
    ClareBear over 3 years

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

    Markup:

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
      AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
      <Columns>
        <asp:BoundField DataField="appID" HeaderText="appID" SortExpression="appID" />
      </Columns>
    </asp:GridView>
    
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
      SelectMethod="GetBookingId" 
      TypeName="AppointmentRepository">
      <SelectParameters>
        <asp:Parameter Name="maximumRows" Type="Int32" />
        <asp:Parameter Name="startRowIndex" Type="Int32" />
      </SelectParameters>
    </asp:ObjectDataSource>
    

    Code-behind:

    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?