ASP.NET GridView Paging Using Linq Query as a Data Source

I am looking for a way to do swap with GridView when I set the data source at runtime using linq query. here is my code:

ETDataContext etdc = new ETDataContext();
var accts = from a in etdc.ACCOUNTs
            orderby  a.account_id
            select new
            {
                Account = a.account_id,
                aType = a.SERVICEs.FirstOrDefault().SERVICE_TYPE.service_type_desc,
                name = a.SERVICEs.FirstOrDefault().service_name,
                Letter_dt = a.create_dt,
                PrimAccthldr = a.PEOPLE.first_name + " " + a.PEOPLE.middle_name + " " + a.PEOPLE.last_name
             };
GridView1.DataSource = accts;
GridView1.BindData();

I have a grid that allows paging, but I get an error that says the PageIndexChanging event was not processed. I searched and found the following:

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
     GridView1.PageIndex = e.NewPageIndex;
     GridView1.DataBind();
}

But this works well when using data, but not with linq. If I add a retry, this will require 7000 entries, which can be a little slow. Does anyone know how to fix paging when using linq like this?

+3
source share

Source: https://habr.com/ru/post/1761847/


All Articles