Keep IT Simple
Register   |  Login  |  About Us  |  Contact Us  |  Career
More than 9 years experiencs in delivering software solutions for eCommerce, Real Estate ERP. We works with .NET Framework, PHP, and many Open Source solutions. Our solutions will certainly assist you and your business.
Web Design & Web Portal Developments. Our professional designers would certainly help your business create the right branding.
Business Solutions, ERP, CRM, POS. We are able to customize all these system based on your actual need. Never let software changes your workflow. Generate meaningful business reports from one fully customized system.
IT Trainings, including Excel VBA, .NET Programming, Sharepoint developments, Mobile Apps developments. Checkout our offers in training programms.
Knowledge Base
Jun 23

Written by: Timothy Mo
6/23/2009 4:49 PM  RssIcon

 Last year I conducted a half day training for a team of developers. The topic was about high performance programming with ASP.NET.

I feel the topic was quite interesting, so before I forget, I should write it down.

This article is about the paging with datagrid.

What is Paging?

Every web developer should at least know what is paging, which is a way to display lots of data by dividing into different pages, and each page should have a fixed size, say, 10 records per page.

Just go to Google.com, do a simple search, that is a live demo for the paging.

Coding paging is very painful process in old ASP 3.0 years. Try coding one if you don't believe. Basically you have to prepare all the page numbers, links for previous page & next page, etc. Btw, code html table to display records also not easy.

So come to .NET time, there is this control called DataGrid (now GridView), which seems to get rid of all those painful programming process by doing some simple settings, like, EnablePaging, PageSize, etc. Too good to be true?

Paging with DataGrid (GridView), the Default Behavior

The steps to use datagrid/gridview to do paging is simple:

  1. Enable property "AllowPaging" and give a value to "PageSize", say, 10.
  2. Choose some property settings for page numbers.
  3. Bind a datasource to the datagrid as usual.
  4.  Done. You should be able to get your records displayed properly in paging view.

Simple to do, but it creates problems.

Issues with The Default Paging Behavior

The main problem with default paging is that the datagrid will become the performance bottle neck in your application.

Imagine you have a 1000 records for a query, and your page size is 10. 

So in this query you should expect 100 pages.

Here is the problem, the default paging will request all 1000 records to be queried out so that the datagrid can actually do the rendering to generate the proper html view.

And users of the application expect to view only 10 records (current page only), but every time they have to query 1000 records out.

And the next problem is, you have to determine whether you want to cache the query result or not. If you store in session or viewstate, you will create an even large problem. If you don't store, that means you have to query database again and again for that 1000 records whenever you click something.

So what should be the solution?

 

Do You Own Paging

There is this property "AllowCustomPaging". Custom paging basically means you have to build all the page numbers by setting some properties.

For example, you need to specify the total number of records. 

The best thing is, you can choose to query only records you want to display.

Assuming for the same 1000 records, you want to display the 5th 10 records only. So you query your database for that 10 records and send to the application layer. From there you bind your datagrid/gridview, with only 10 records. It is going to be much faster. And imagine if the number of records grow to 10,00000? 

Default paging will fail you during performance testing for that.

How To Implement Custom Paging

There are tons of good articles teaching you how to do custom paging. Over here I will just summarize the key points and I will give reference to those good articles.

The first thing, you must know how to do paging with Stored Procedure. You will need to create a Stored Procedure with parameters to support paging. Parameters like, pagesize, pagenumber, must be supported by the Stored Procedure.

There is a good article to teach you about that: http://www.4guysfromrolla.com/webtech/062899-1.shtml 

Then, you need to program your datagrid/gridview to support the custom paging. Basically there are some simple settings to set and a bit additional coding to handle page numbers.

And this article is a good reference to custom paging implementation: http://www.c-sharpcorner.com/UploadFile/mosessaur/custompaging08202006185153PM/custompaging.aspx

Paging with LINQ

Now there is relatively easier way to do paging without fetching all the records. 

Some sample code like this:

//used by LINQ to SQL

public static IQueryable Page(thisIQueryable source, int page, int pageSize)

{

return source.Skip((page - 1)*pageSize).Take(pageSize);

}

//used by LINQ

public static IEnumerable Page(thisIEnumerable source, int page, int pageSize)

{

return source.Skip((page - 1)*pageSize).Take(pageSize);

}

From the code, you can easily see the concept is very similar to what we did in Stored Procedure. 

The complete article, please read here: http://solidcoding.blogspot.com/2007/11/paging-with-linq.html

 

Tags:
Categories:

10 comment(s) so far...


Gravatar

Re: High Performance .NET Programming Practice (1)

Good to read interesting posts on your blog. Thanks.
www.rapidsharemix.com

By Odysseus on   12/23/2009 9:21 PM
Gravatar

Re: High Performance .NET Programming Practice (1)

Then, you need to program your datagrid/gridview to support the custom paging. Basically there are some simple settings to set and a bit additional coding to handle page numbers.swtor credits
swtor credits
swtor credits
aion kinah

By runescape gold on   11/3/2011 9:56 AM
Gravatar

Re: High Performance .NET Programming Practice (1)

French archaeologists Denis Vial and Agueda Vilhena Viala, in 1984, the archaeological sites located in shelters on rocks that was called Cave of the Lost, where walls display paintings dated by carbon-14 between 3630 and 4610 years, featuring as Zone Prehistoric.
buy wow gold : www.mmogoldsstore.com/

By ffxiv gil on   11/4/2011 6:08 PM
Gravatar

Re: High Performance .NET Programming Practice (1)

As opposed to making use of its conventional louis vuitton speedy supplies, this season Louis Vuitton has released a brand new series-the Louis Vuitton Slightly Denim. Just as its name tells, the bag is slight in weight for the light denim it made use of cheap louis vuitton and will cheer you up inside the downturn economy with its easy but sophisticated color.Pretty much for every single woman, besides the outfits, handbags are really a further kind of important accessories in her wardrobes. Nowadays, handbags aren't restricted towards Tiffany and CO the standard function of holding every day essentials. Shopping for a Louis Vuitton monogrammed Vernis purse is an investment within your fashion louis vuitton artsy future. The LV and 4 pointed flower monogram are renowned world-wide Tiffany jewelry outlet. In truth, the Louis Vuitton brand name is one of the most pricey names within the globe, products notwithstanding.One thing that you simply need to normally keep in mind regarding the Louis Vuitton brand is that the firm behind coach factory outlet it's a staunch defender of classical aesthetics and conventional high fashion motifs.The bag marries modest capacity and functionality louis vuitton luggage. Firstly, the bag is created from endurable Monogram Denim canvas and not-so-easy-to-stain micro fiber louis vuitton neverfull lining.Actually, they're widely deemed as perfect symbols expressing people's fashion taste and personality.

By uggs outlet on   1/10/2012 5:08 PM
Gravatar

Re: High Performance .NET Programming Practice (1)

using the financial system escalating quickly of China, the lexia 3 market also stays a point go up rapidly, undoubted the car for the the majority of chinese language program experienced been not just a much cry, but in meantime they Renault can clip do not retain up using the development's movement using the element which extremely Digimaster three worth inside the existence safety.

By dsa on   1/30/2012 4:41 PM
Gravatar

Re: High Performance .NET Programming Practice (1)

Fashion could be divided into two groups: conceptual and literal louis vuitton neverfull PM. Conceptual pieces hint at their inspiration or theoretical underpinnings, whilst literal items just go proper out louis vuitton speedy 45 and tell you where they came from cheap louis vuitton speedy and why they're here. For the handbags of Diane von Furstenberg Fall 2012 louis vuitton speedy sale, factors got really literal.Currently you'll get photos of day 3 and day 4 of my handbag alternatives through New York Fashion Week louis vuitton neverfull MM. Even with ample planning, Fashion Week louis vuitton speedy 25 features a strategy to make louis vuitton sale absolutely everyone really feel slightly crazed as well as a lot behind on work.much to my dismay. Alexander Wang Fall 2012 louis vuitton speedy mini yielded enough accessories for us to get an impression of what we really should anticipate come fall, but too few to actually satisfy my curiosity as a louis vuitton neverfull GM fangirl. I'll be waiting impatiently for pictures from the complete line to emerge.When I watch a runway show, I like to do points a bit bit backward; rather than reading louis vuitton speedy the provided notes before louis vuitton neverfull the show begins, I like to view the louis vuitton luggage initial to view if the impressions I had as a blank slate line up with what the designer had in mind.

By louis vuitton sale on   2/15/2012 9:37 AM
Gravatar

Coach Outlet

Chanel 2.55 Bags will probably be popular for Chanel Handbags Cheap as flavor for everyone.Replica Chanel Watches might be refreshing and Chanel J12 Watch Replica appeal in aroma.Chanel J12 Watch which might be imported is often filtered without having great in taste.Subsequently,the Cheap Air Jordans might do more effective to stick to enable you to serving New Jordan Shoes.Nonetheless,True Religion Jeans Outlet that may be locally and even its distinct Cheap True Religion Jeans are unchanging.Within Coach Outlet as well as The North Face Outlet,you will discover no constraints.Coach Outlet may use to deliver that nation's various sorts.The Coach Outlet is often a must-consider one due to containing breathtakingly wonderful multi-purpose Coach Outlet.

By Coach Outlet on   2/18/2012 10:23 AM
Gravatar

http://www.franklinandmarshalloutlets.org/

franklin marshall outlet
franklin and marshall outlet
franklin & marshall outlet
franklin marshall online
franklin and marshall online
franklin marshall clothing
franklin and marshall clothing
Mens Franklin & Marshall Franklin and Marshall Hoodie Sweatshirts Franklin & Marshall Jackets Franklin and Marshall Long Sleeved T-Shirts Franklin and Marshall Knitwear Franklin Marshall Fleece Pants Franklin & Marshall Polo T-shirts Franklin and Marshall Short Tees Franklin Marshall Shirts Franklin & Marshall Short Pants Franklin and Marshall Vest Franklin & Marshall Down Jackets Womens Franklin and Marshall Franklin and Marshall Jackets Franklin & Marshall Hoodie Sweatshirts Franklin Marshall Long Sleeved T-Shirts Franklin and Marshall Polo T-shirts Franklin Marshall Short Tees Franklin & Marshall Fleece Pants Franklin and Marshall Short Pants Franklin and Marshall Dresses Franklin & Marshall Vest - Franklin Marshall Accessories Franklin and Marshall Bags Franklin Marshall Hats Franklin & Marshall Scarf Jeans True Religion Mens True Religion Jeans Womens True Religion Jeanschristian louboutin outlet
christian louboutin online
christian louboutin outlet online
christian louboutin sale
Christian Louboutin Shoes
Christian Louboutin Sandals
Christian Louboutin Wedges
Christian Louboutin Slingbacks
Christian Louboutin Evening
Christian Louboutin Pumps
Christian Louboutin Peep-Toe Pumps
Christian Louboutin Mary Jane Pumps
Christian Louboutin Pointed Toe Pumps
Christian Louboutin Sandal Booties
Christian Louboutin Ankle Boots
Christian Louboutin Boots
Christian Louboutin Over The Knee Boots
Christian Louboutin Flats
Womens Christian Louboutin Sneakers
Mens Christian Louboutin Sneakers
Mens Christian Louboutin Shoes

By Franklin Marshall Outlet on   4/13/2012 10:31 PM
Gravatar

Air Jordan Shoes

A Cycling Jersey that is good for road tours is going to have Georg Jensen in particular to recommended Tiffany Rings series. And Juicy Couture Bags also bring very creative and entertaining slogans to work in their Juicy Couture Outlet with slogans. The North Face's women's nuptse jacket is made from 700 Hungarian goose down fill. But buying True Religion Jeans doesn't require your emotional impulses galore. It is really a classical Air Jordan Shoes model in the world today. Online store offers you cheapest Nike Air Jordan shoes worldwide in an impeccable manner. A Cycling Shorts made for road touring will have fittings for panniers. While Tiffany & Co series because of inspiration from the beautiful water. Juicy Couture Laptop Bag is a baby in the fashion industry. Another great feature of North Face Jacket is its loft. Buying True Religion Outlet is done with a fixed set of norms and rules. Retro Jordan 11 is very magnificent and immaculate shoe by any means. Roberto Carlos have had used Cheap Jordan Shoes during the pivotal football matches quite earlier. From a technical point of view Bike Jersey is possible to adapt any bike. Many people felt strange why I always wore a Tiffany Necklace in my neck. These True Religion Shorts look great with a plain looking black leather belt. Air Jordan Retro is a very brightening shoe.

By Air Jordan Shoes on   5/4/2012 10:50 AM
Gravatar

http://www.nikelunareclipseshoes.us/

nike lunar shoes lunar eclipse nike nike lunar eclipse nike lunar Air Force 1 Air Force 1 Heels Hi-Top Air Jordan Air Jordan 2011 Air Jordan 2012 Air Jordan III(3) Air Jordan V(5) Jordan 3.5 Spiziker Jordan Alpha Trunmer Jordan Heels Jordan Melo Jordan Retro XI(11) Jordan Wade Air Max Air Max 2009 Heels Air Max Classic BW Air Max Griffey Air Max LTD Air Max Skyline Air Max Tailwind +4 Air Max Terra Ninety Air Max Zenyth Nike Air Max 180 Nike Air Max 2009 Nike Air Max 2010 Nike Air Max 2011 Nike Air Max 2012 Nike Air Max 24-7 Nike Air Max 360 Nike Air Max 87 Nike Air Max 89 Nike Air Max 90 Nike Air Max 91 Nike Air Max 93 Nike Air Max 95 Nike Air Max ACG Nike Air Max Barkley Nike Air Max Tn Nike Max Alpha 2012 Barefoot Nike Free Run Barefoot Free Run 3.0 V2 Barefoot Free Run 3.0 V3 Barefoot Nike Free 5.0 V4 Barefoot Nike Free 7.0 Barefoot Nike Free Run Barefoot Nike Free Run+ 2 Barefoot Nike Free Run+ 3 Barefoot Nike Free Tr Fit Dual Fusion St 2 Football Soccoer Nike Dunk SB Nike Dunk Block Heels Hi-Top Nike Dunk Block Heels Lo-Top Nike Dunk Heels Hi-Top Nike Dunk Heels Lo-Top Nike Lunar Lunar Orbit Nd Lunar Rejven8 Mid LunarEclipse+ 2 Nike Lunaracer+ 2 Nike LunarEclipse+ Nike LunarElite+ Nike LunarElite+ 2 Nike LunarFly+ 2 Nike LunarGlide + Nike LunarGlide +2 Nike LunarGlide+ 3 Nike LunarHaze Nike LunarMX+ Nike LunarSwift Nike Shox Nike Shox NZ Nike Shox R4 Nike Shox Turbo Nike Zoom Air GO LWP Hyperdunk 2011 Low Lebron VIIII 9 Zoom Kobe VI Zoom Kobe VII Zoom Lebron VII Zoom Rookie

By nike lunar shoes on   5/10/2012 9:38 PM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
Knowledge Base
Privacy Statement Terms Of UseCopyright 2008 - 2011 by wGrow Technologies Pte Ltd