开发者

Why doesn't asp.net make pagination efficiently on gridview controls?

I have a site with thousands of records and every time I make an action the gridview send around 300kb by ajax. I try to make a custom pagination maintaining the ajax functionality,开发者_如何学C sorting, but it is so complicated. I search for a hack to this but I don't find anything.

Links about: http://www.nikhedonia.com/notebook/entry/efficient-paging-for-gridview/ http://kpumuk.info/asp-net/gridview-with-custom-digg-like-pager/

@mellamokb, this is the way I databind the gridview

CODE:

Dim res = From r In dc.Reservas _
    From u In dc.UsuariosData Where r.usr_Id = u.usr_Id _
    From c In dc.Campings Where c.camp_Id = r.camp_Id And r.sta_Id <> 2 _
    From rec In dc.OrdenesRegistros Where rec.rec_Id = r.rec_Id _
    From o In dc.Ordenes Where o.ord_Id = rec.ord_Id _
    From p In dc.Pagos Where p.pay_Id = o.pay_Id _
    From z In dc.Zonas Where z.zon_Id = r.zon_Id _
    Select New With {.res_Id = r.res_Id, _
        .usr_NickName = u.usr_NickName, .usr_Name = u.usr_Name, _
        .usr_LastName = u.usr_LastName, .usr_Email = u.usr_Email, _
        .usr_Cel = u.usr_Cel, .camp_Name = c.camp_Name, _
        .res_CreationDate = r.res_CreationDate, _
        .pay_Name = p.pay_Name, _
        .sta_Id = r.sta_Id, .camp_Id = c.camp_Id, .res_StartDate = r.res_StartDate, _
        .res_EndDate = r.res_EndDate, .zon_Id = z.zon_Id}

Session("datosGridView") = res
GridView_ZC.DataSource = Session("datosGridView")
GridView_ZC.DataBind()


The pagination should be handled by the data source control. If you are using a LinqDataSource control, then it should do the pagination with AutoPage="true" AFAIK.

Edit

Your data source has no pagination, so all of the data has to flow to the GridView before the GridView can paginate it. Your LINQ-to-SQL query returns all records.

You want to use a "smart" data source, like a LinqDataSource control. The easiest way is to declare a LinqDataSource, bind the GridView to the data source in the markup, and then override the Selecting event of the LinqDataSource to specify your custom data retrieval logic:

<asp:LinqDataSource ID="MyDataSource" runat="server"
    OnSelecting="MyDataSource_Selecting" AutoPage="true" AutoSort="true">
</asp:LinqDataSource>

<asp:GridView ID="MyGridView" DataSourceID="MyDataSource" ... >

The code-behind:

Protected Sub MyDataSource_Selecting(sender As Object, _
        e As LinqDataSourceSelectingEventArgs)

    Dim dataContext As New MyDataContext
    e.Result = ' Put LINQ-to-SQL code here

End Sub


Check this : http://www.seila.gov.kh/eang/ASPNET2.0/Web_2.0_With_ASP_NET_3.5.pdf There a few chapters about optimization and perfomance, I recall reading something about gridview controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜