Reputation: 871
How do I split data into pages on ASP.Net?
I'm looking for something like what Google does when you have too many search results and it splits them into x number of pages.
Upvotes: 1
Views: 1358
Reputation: 340
Use a GridView and the LinqDataSource.
It will do it all for you.
See:
http://msdn.microsoft.com/en-us/library/bb470363.aspx
and:
http://msdn.microsoft.com/en-us/library/bb547113.aspx
Upvotes: 0
Reputation: 26599
It would depend entirely on the content. If it's a simple datagrid you can use the built in datagrid paging. If the data is coming from SQL though, I'd advise building a generic "paging control" and using the paging functionality of SQL to only pull back the data you want to see.
If it's SQL 2005 (or above) paging is nice and easy:
SELECT Description, Date
FROM (SELECT ROW_NUMBER() OVER (ORDER BY MyCol DESC) AS Row, Desc, Date FROM MyTable)
AS MyTableWithRowNumbers
WHERE Row >= 1 AND Row <= 10
Upvotes: 5