Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

A worked shopping cart example

A shopping cart is a useful teaching example because it touches almost every idea in this track at once, without being large.

The pieces

  • A product list. Reads the catalogue from a database and shows it.
  • An add button. Adds one product to the visitor's cart.
  • The cart itself. Held in session while the visitor browses.
  • A checkout page. Writes the order to the database and clears the cart.

Why the cart lives in session

A cart belongs to one visitor and lasts for one visit, which is exactly what session state offers. When the visitor checks out, the order moves into the database where it can last forever.

The important lesson. Notice how each layer has one job. Pages present, session remembers, the database persists. Keeping those roles separate is what makes an application maintainable.

Where to see a working version

The Beginner Web Site Kit includes a complete shopping cart sample with source code and a database you can restore. Read this lesson first, then open the code and follow one page at a time.

To store and read the catalogue data yourself, continue to talking to a database with ADO.NET.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.