Solution: The Data Source Does Not Support Server-Side Data Paging With GridView

Friends,

While working with GridView, I encountered an issue when binding the data to the GridView. The error message read as “The data source does not support server-side data paging“. Initially I thought this was related to paging functionality of the GridView and looked into that, but that was not the solution. After doing a bit of searching, I discoverd that the reason for this error was the way a source is bound to the GridView. I will explain.

Initially this was my LoadData():
  1. private void LoadData()   
  2. {   
  3.       ProductInventory[] lines = GetData();   
  4.       grdRows.DataSource = lines.Where(t => t.ProductID.StartsWith(tbSearch.Text));   
  5.       grdRows.DataBind();   
  6. }   
Here I am trying to get some data based on a filter using LINQ and applying it directly to the GridView. This was the main reason of the error. I just converted this resultset to a List using ToList() and voila, it works. The modified LoadData looks like the following:
  1. private void LoadData()   
  2. {   
  3.       ProductInventory[] lines = GetData();   
  4.       grdRows.DataSource = lines.Where(t => t.ProductID.StartsWith(tbSearch.Text)).ToList();   
  5.       grdRows.DataBind();   
  6. }   
In technical words from StackOverflow, “You can't use an IQueryable object to data bound to a GridView and still use Paging and Sorting. You must return a List to the GridView using the ToList() method.”

I hope you like this! Keep learning and sharing! Cheers!