views:

313

answers:

2

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.

+1  A: 

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
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
take a gander at this article. http://www.codeproject.com/KB/aspnet/PagingWithODS.aspx
Al W
+2  A: 

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
I am trying to do this way, considering this link: http://stackoverflow.com/questions/475982/asp-net-datagrid-and-custom-paging
Victor Rodrigues
which is the same :) notice the code in page load, you can't miss the virtualitemcount
eglasius
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
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
Freddy, thanks! It worked :D
Victor Rodrigues