Click here to Skip to main content
15,908,626 members
Articles / Web Development / ASP.NET
Article

Shopping Cart using C#.NET, Web Forms and SQL Server

Rate me:
Please Sign up or sign in to vote.
4.41/5 (62 votes)
20 Apr 20041 min read 693.2K   36.2K   153   164
Shopping cart using C#.NET, Web Forms and SQL Server.

Introduction

This application is a Shopping Cart where users can select items and place an order. I have added the features of login, and adding new users if user does not exist. Validations are performed wherever needed like email format validation, zipcode etc.

Fig. 1

Image 1

Database: For the purpose, I have used the NorthWind database and SQL Server.

The two main tables used are:

  1. Products table
  2. Order Details table.

I have used two classes:

C#
public class CartRow
{
    public string id;
    public string name;
    public string price;
    public string items;
};
public class Cart
{
    public System.Collections.ArrayList list = new ArrayList(20);
};

The two main web-forms are Main.aspx and CheckOut.aspx. Main.aspx contains a grid showing all items present in the products table along with the price per unit and the quantity per unit. Fig 1 shows the Main.aspx page, where user can select items from the products grid (left). As he selects an item, it is added to his cart and the item is displayed in the right panel. The total price is displayed in the label above. As the user adds more items to his cart, the recalculated price is shown. Upon clicking the clear cart button, the cart gets empty.

If the user now wants to finalize the order and presses the CheckOut button, he is redirected to the Login.aspx page (Fig 2). I have set the default username as “user” for the sample and password is “u”.

Fig 2.

Image 2

And finally, the user is asked to enter the Credit Card number, billing PIN code and his email address. It does the client side validations and then confirms the order placed by sending a mail to the user as shown in (Fig 3).

And the order is finalized. For more advanced shopping cart, this information plus the item information has to be stored in some database.

Fig 3

Image 3

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionPlease send Database Details which you used to create Shopping cart Pin
guru4IAS30-Jun-11 0:39
guru4IAS30-Jun-11 0:39 
GeneralDo you have a simple shopping cart in ASP.net using VB code Pin
aradhakrishnan4-Feb-11 13:38
aradhakrishnan4-Feb-11 13:38 
Generalrequesting to send database Pin
Lakshmisaraswathi18-Jan-11 20:23
Lakshmisaraswathi18-Jan-11 20:23 
GeneralRe: requesting to send database Pin
DarshanGowda00917-Aug-11 19:52
DarshanGowda00917-Aug-11 19:52 
Generalpls send me database Pin
hellovatsu1-Dec-10 5:04
hellovatsu1-Dec-10 5:04 
GeneralRe: pls send me database Pin
DGamer2-Dec-10 9:17
DGamer2-Dec-10 9:17 
QuestionIs anyone here? Pin
DGamer26-Nov-10 16:59
DGamer26-Nov-10 16:59 
RantAuthor of this Script is not actively participating on this site. Pin
DGamer20-Nov-10 13:08
DGamer20-Nov-10 13:08 
Confused | :confused: The author has not responded to any post here. I added the author to my msn messenger email contact list. But still no reponse. Let's try and help each other, perhaps collectively we can resolve each others issues. Reply to this post with your e-mail and let's setup a group chat on msn messenger. It would be helpful if someone with knowledge of asp and c# participate. Remember why you came to this site, and downloaded this script. Let's work togetherSmile | :)


Three things about this script I need to modify or fix. Seperating the shopping cart table from the products page. I want the shopping cart to show in an iframe. I already accomplished this by targeting the iframe, but the products table also displays there. It updates at the target, not on the main page. But then, the shopping cart also displays on the main page. Which also happens to be an iframe.


I need to setup multiple categories, so when a link such as cameras is clicked, another table is queried displaying the cameras table. I did create another table and named it cameras within the northwind database. Then copied main.aspx renaming it as cameras.aspx. I did the same for main.aspx.cs and main.aspx.resx. I then edited cameras.aspx and named the codefile to cameras.aspx.cs. Changed the queries from products to cameras inside both files. But it didn't work, the application errored.


I need to have images in the products table, but have not been successful at adding them. Also, the add to cart link would be more friendly to the touch screen if it were a graphic button. A details page would be helpful to customers to provide more information than the items name and price.


A couple of other things I noticed was the order details are not included in the emails or the database. Also, new users are not validated or added to the database. Although, I commented out the login page so that the next page that loads is the checkout. But then, I don't require credit card numbers or billing zip codes from the users right now. I am using this on my intranet in my store as a shopping portal, and have designed this to be used from a touch screen.. After orders are submitted, they are sent to my email server. I use popup peeper, it checks emails every single minute. Then pops up like msn messenger notifying me of a new email. I open the emails and pull the items from the stock room, then scan them at the register and complete the sale. Upon submission of order, the shopping cart should cleared. If you close and open the page again, you will see the items from the previous cart still there.


Design wise, it is nearly complete. However, I need the sql query results to be more graphical. I have been at this for weeks, first getting the sql server setup, and configuring the script to connect to it.


Here is what I have so far:


Video of my Shopping Portal
GeneralRe: Author of this Script is not actively participating on this site. Pin
Member 1007235322-May-13 23:01
Member 1007235322-May-13 23:01 
GeneralUser ID and Password + Order details Pin
DGamer10-Nov-10 10:09
DGamer10-Nov-10 10:09 
Generalpls send me database pls....... Pin
udaya kumar g s2-Nov-10 4:21
udaya kumar g s2-Nov-10 4:21 
GeneralRe: pls send me database pls....... Pin
DGamer2-Nov-10 12:00
DGamer2-Nov-10 12:00 
GeneralRegarding Database Pin
DGamer1-Nov-10 17:31
DGamer1-Nov-10 17:31 
Generaldatabase required urgently Pin
preetibamania27-Sep-10 4:06
preetibamania27-Sep-10 4:06 
GeneralRe: database required urgently [modified] Pin
DGamer2-Nov-10 12:01
DGamer2-Nov-10 12:01 
Generaldatabase Pin
nitinmodi20-Sep-10 8:47
nitinmodi20-Sep-10 8:47 
GeneralRe: database [modified] Pin
DGamer2-Nov-10 12:01
DGamer2-Nov-10 12:01 
GeneralDatabase Pin
popokatipetl4-Sep-10 22:53
popokatipetl4-Sep-10 22:53 
GeneralRe: Database [modified] Pin
DGamer2-Nov-10 12:01
DGamer2-Nov-10 12:01 
GeneralRequesting Database Pin
apachex26-Aug-10 22:39
apachex26-Aug-10 22:39 
GeneralRe: Requesting Database Pin
DGamer2-Nov-10 12:22
DGamer2-Nov-10 12:22 
GeneralPlease send me the database Pin
tneuber25-Aug-10 12:30
tneuber25-Aug-10 12:30 
GeneralRe: Please send me the database Pin
DGamer2-Nov-10 12:22
DGamer2-Nov-10 12:22 
GeneralDatabase Pin
minkzzii24-Aug-10 19:40
minkzzii24-Aug-10 19:40 
GeneralRe: Database Pin
DGamer2-Nov-10 12:23
DGamer2-Nov-10 12:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.