The data source does not support server-side data paging
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.
Paging in Gridview - The data source does not support server-side data paging
The exception most possibly come from this line:
gwActivity.DataSource = cmd.ExecuteReader();
AFAIK, SqlDataReader
used by ExecuteReader()
method can't be used to bind as GridView
data source because it is forward-only reader and doesn't support paging feature. Use another data source like SqlDataAdapter
which support bi-directional data reading as given below:
public void BindGridviewActivity()
{
/*************Connectionstring is located in Web.config ******************/
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("SELECT T1.[ActivityID] FROM [BI_Planning].[dbo].[tlbActivity]", con);
con.Open();
var da = new SqlDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds);
if (ds.Tables.Count > 0)
{
gwActivity.DataSource = ds.Tables[0];
gwActivity.DataBind();
}
}
}
The data source does not support server-side data paging.why?
That's because when you turn this property on the gridview uses its built-in paging functionality which can only work with data sources that extend the ICollection interface. ..in this case your object (query19) doesn't support it. You should be able to make it work by inverting the linq extension method calls...instead of doing this....
ToList ().Distinct ()
Do this....
Distinct().ToList()
That should work
The data source does not support server-side data paging when using a front-end collection
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.
See this DevToolShed Article for more information:
http://www.devtoolshed.com/content/gridview-objectdatasource-linq-paging-and-sorting
Related Topics
..The Underlying Connection Was Closed: an Unexpected Error Occurred on a Receive
Net Core: Execute All Dependency Injection in Xunit Test for Appservice, Repository, etc
"Not In" Clause in Linq to Entities
How to Have a Loop in a Windows Service Without Using the Timer
C# String Replace with Dictionary
Linq to Find Series of Consecutive Numbers
MVC 4 How Pass Data Correctly from Controller to View
C# Automatic Property Deserialization of JSON
Identifying Nhibernate Proxy Classes
Unlock Windows Programmatically
C# - Making All Derived Classes Call the Base Class Constructor
Testing Equality of Arrays in C#
Why Does This Simple .Net Console App Have So Many Threads
Wpf/Mvvm - How to Handle Double-Click on Treeviewitems in the Viewmodel