LINQ - The data source does not support server-side data paging.

Asked By sam foryou on 02-Mar-12 12:40 AM
if i am enabling paging in gridview it is not working other wise it is fine .. 


 var movies = GetMovies();
    this.GridView1.DataSource = from m in movies
            where m.ReleaseDate < DateTime.Parse("1/1/2026")
            select new { m.Title, m.ReleaseDate };
    this.GridView1.DataBind();



public class Movie
{
    public string Title { get; set; }
    public string Director { get; set; }
    public int Genre { get; set; }
    public int RunTime { get; set; }
    public DateTime ReleaseDate { get; set; }
}
Somesh Yadav replied to sam foryou on 02-Mar-12 12:43 AM

For those that are getting this error but implementing:

IEnumerable<T> or 
IEnumerable or
IList<T> or
IDictionary<T1, T2>.

You need to implement ICollection (the non-generic one) for you to get passed the "The data source does not support server-side data paging" error.

sam foryou replied to Somesh Yadav on 02-Mar-12 12:46 AM
if i am doing like that what will happen in background.. can u explain??
dipa ahuja replied to sam foryou on 02-Mar-12 05:32 AM
Implement the paging in gridview

Here is the simple example of gridview paging:
 
Set the AllowPaging = True for gridview and write this code in codebehind
 
protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
     bindGrid();
   }
}
void bindGrid()
{
   SqlDataAdapter da = new SqlDataAdapter("select * from TableName", "Connection String");
   DataTable dt = new DataTable();   
  da.Fill(dt);
   GridView1.DataSource = dt;
   GridView1.DataBind();
}
 
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   GridView1.PageIndex = e.NewPageIndex;
   BindGrid();
   //Bind Grid
}