Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net pagination best practice

I'm using linq to sql to get my data, when I set the page size on my data grid and the user selects page 2, I get a postback and I re-read all the data to show the second page. I suspect there should be a better way of doing this, a way that ends up reading just the data I need to show. I was wondering if there are any code samples...

like image 831
Ali Shafai Avatar asked Dec 13 '25 04:12

Ali Shafai


2 Answers

You should really be looking at the Skip and Take methods.

See ScottGu's post on LINQ to SQL (Part 3), and search the page for "Paging our Query Results" - this has some nice examples.

Alternatively, if you use the LinqDataSource control, and you're talking to a SQL 2005 or 2008 database, you should get this behaviour automatically. LINQ to SQL (Part 5) covers that.

like image 166
Zhaph - Ben Duguid Avatar answered Dec 14 '25 20:12

Zhaph - Ben Duguid


If you want really ease the database load, take a look at client-side paging...

like image 45
Tomas Aschan Avatar answered Dec 14 '25 18:12

Tomas Aschan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!