Click here to Skip to main content
15,886,137 members
Articles / All Topics

Solution: The Data Source Does Not Support Server-side Data Paging with GridView

Rate me:
Please Sign up or sign in to vote.
4.89/5 (4 votes)
28 Sep 2014CPOL 18.9K   2  
Solution for error: "The data source does not support server-side data paging with GridView"

While working with GridView, I faced an issue while binding the data to 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 search, I found the reason of this error was the way a source is bound to the GridView. I will explain it to you here.

Initially, this was my LoadData().

C#
private void LoadData()
{
    ProductInventory[] lines = GetData();
    grdRows.DataSource = lines.Where(t => t.ProductID.StartsWith(tbSearch.Text));
    grdRows.DataBind();
}

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 below:

C#
private void LoadData()
{
    ProductInventory[] lines = GetData();
    grdRows.DataSource = lines.Where(t => t.ProductID.StartsWith(tbSearch.Text)).ToList();
    grdRows.DataBind();
}

In technical words from StackOverflow, “You can’t use an IQueryable object to data bind to a GridView and still use Paging and Sorting. You must return a List to the GridView using the ToList() method.

Hope you like this! Keep learning and sharing! Cheers!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Rebin Infotech
India India
A passionate developer with over 10 years of experience and building my software company code by code. Experience withMS Technologies like .Net | MVC | Xamarin | Sharepoint | MS Project Server and PhP along with open source CMS Systems like Wordpress/DotNetNuke etc.

Love to debug problems and solve them. I love writing articles on my website in my spare time. Please visit my Website for more details and subscribe to get technology related tips/tricks. #SOreadytohelp

Comments and Discussions

 
-- There are no messages in this forum --