0

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.

Victor Rodrigues
  • 11,353
  • 23
  • 75
  • 107

2 Answers2

2

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;"

eglasius
  • 35,831
  • 5
  • 65
  • 110
  • I am trying to do this way, considering this link: http://stackoverflow.com/questions/475982/asp-net-datagrid-and-custom-paging – Victor Rodrigues Mar 10 '09 at 18:08
  • which is the same :) notice the code in page load, you can't miss the virtualitemcount – eglasius Mar 10 '09 at 18:39
  • you also can't miss the AllowCustomPaging - do you mean you tried that, or that you are now trying that? / if you already tried, review it carefully again – eglasius Mar 10 '09 at 18:40
  • btw, just to be clear, that is for your code to handle the paging (in your case with the sp), you just specify the current page to display on the DataSource. – eglasius Mar 10 '09 at 18:42
1

If you use an ObjectDataSource control as the DataSourceID of the GridView then it works pretty seamlessly. The ObjectDataSource controls has a couple of parameters where you can tell it the names of the PageIndex and MaxRows properties.

Al W
  • 7,539
  • 1
  • 19
  • 40
  • I use ADO connection, command, etc, and after loading results in a list of objects (my entity classes), I make datagrid.DataSource = List; – Victor Rodrigues Mar 10 '09 at 17:26
  • take a gander at this article. http://www.codeproject.com/KB/aspnet/PagingWithODS.aspx – Al W Mar 10 '09 at 17:55