Search code examples
c#asp.net.netdata-bindingpagination

Can I use <asp:dataGrid> pager with database paging performance?


I have a store procedure that handles paging at database level, receiving @PageSize and @PageIndex. I can create another to return @PageCount, given a page size.

Can I make a datagrid do paging at database level without having to develop it outside the control, using the control pager?

It seems default use of datagrid paging receives all query result, and does paging outside the database. It is not good for us, an unnecessary overload.


Solution

  • Set AllowCustomPaging="true" on the aspx. And when databinding do:

    mygrid.VirtualItemCount = pageCount; 
    mygrid.DataSource = mysource; 
    mygrid.DataBind();
    

    Based on your comment "I use ADO connection, command, etc, and after loading results in a list of objects (my entity classes), I make datagrid.DataSource = List;"