Data source does not support server side data paging

I have a GridView on my screen and it needs to enable 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 for:

 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 get this error:

The data source does not support pagination on the server side.

What am I doing wrong?

+55
sorting c # linq gridview
Nov 02 '09 at 13:19
source share
8 answers

Simple ToList() in your var result should work.

Edit : Since BornToCode is explained in the comments below my answer, the cause of the error is that the data source must implement ICollection. IEnumerable does not, when you do ToList() , it converts it to a list that implements ICollection.

+128
Nov 02 '09 at 13:26
source share

You can also use a generic List<T> . See Example 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.

+3
May 14 '10 at 10:48
source share

.ToList() at the end of the DataSource, I assign a job to me, as shown below:

 gvCaseLabelsLeft.DataSource = caseLabelsList.OrderBy(c=>c.caseLabelNumber).ToList(); 
+2
Dec 13 '13 at 17:42
source share

I 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(); } 
+1
Jun 09 2018-12-12T00:
source share

In ObjectDataSource just add enablePaging="true" , which will work.

0
Mar 22 '11 at 19:23
source share

LINQ query:

ProductController.cs:

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

ProductModel.cs:

 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(); } 
0
Nov 21 '15 at 4:51 on
source share

If you use SqldataReader, then it does not support paging.

The solution to this error is to use data sources, such as collections of shared lists, data tables, data sets, etc., for linking a GridView.

0
Feb 28 '18 at 11:45
source share

Try this article https://www.aspsnippets.com/Articles/ASPNet-GridView-The-data-source-does-not-support-server-side-data-paging.aspx

in conclusion, try using 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; con.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { GridView1.DataSource = sdr; GridView1.DataBind(); } con.Close(); } } } protected void OnPaging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; this.BindGrid(); } <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true" OnPageIndexChanging="OnPaging"> <Columns> <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" /> <asp:BoundField DataField="ContactName" HeaderText="ContactName" /> <asp:BoundField DataField="Country" HeaderText="Country" /> </Columns> 

0
Apr 30 '19 at 2:36
source share



All Articles