Professional Documents
Culture Documents
Ads by CouponDropDown
HOME AJAX ASP.NET C# CRYSTAL REPORTS GRIDVIEW JAVASCRIPTS JQUERY SHAREPOINT 2010 SQL SERVER VB.NET WINDOWS FORMS
Search
81
Like
Send
16
Tw eet
Like
Follow @dotnetfreak
We're on
Follow
Subscribe by E-mail
Subscribe
First of all we need to create a ShoppingCart class, for this right click on solution explorer and add
new class, name it ShoppingCart.cs
Write this code in ShoppingCart.cs class
namespace ShoppingCartExample
{
/// <summary>
/// Summary description for ShoppingCart
/// </summary>
[Serializable]
public class CartItem
{
private int _productID;
private string _productName;
private string _imageUrl;
csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html
1/59
7/4/13
Recent Posts
Configure Unique Document IDs Feature In
SharePoint 2010
Asp.Net Bind Populate DropDownList With JQuery
And XML
AjaxFileUpload AsyncFileUpload In ModalPopUp
Extender Asp.Net
Allow Enable Anonymous Access In SharePoint 2010
Sites
Ajax AutoCompleteExtender In Master Page Asp.Net
Loading...
Ads by CouponDropDown
public Cart()
{
if (this._items == null)
{
this._items = new List<CartItem>();
this._dateCreated = DateTime.Now;
}
}
public List<CartItem> Items
{
get { return _items;}
set { _items = value;}
}
public void Insert(int ProductID, double Price,
int Quantity, string ProductName, string ImageUrl)
{
int ItemIndex = ItemIndexOfID(ProductID);
if (ItemIndex == -1)
{
csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html
Search
2/59
7/4/13
Now to create Products page, add a new webform and name it Products.aspx, add sqldataSource
and configure it for select statement,
read this for how to configure SqlDataSource
Add a DataList Control on the page and make SqlDataSource1 it's source.
Configure Datalist according to below mentioned source
csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html
3/59
7/4/13
Now add a new webform and name it ProductDetails.aspx , this page is used for showing
details for selected product from product catalog page, again add a SqlDataSource and DataList
Control on this page and configure them according to source shown below, this time datalist is
populated using QueryString Parameters.
csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html
4/59
7/4/13
Now right click on solution explorer and add new web user control, name it CartControl.ascx
In design view of this control add a new GridView control and a label below gridview, html shource
of this control should look like this
Open web.config file and add this section for enabling anonymous users to add items to cart
<system.web>
<authorization>
<allow users="?" />
<allow roles="admin" />
</authorization>
<roleManager enabled="true" />
<authentication mode="Forms" />
<compilation debug="true">
</compilation>
</system.web>
<system.web>
<anonymousIdentification enabled="true"/>
<profile enabled="true">
<properties>
<add name="SCart" serializeAs="Binary"
type="ShoppingCartExample.Cart"
allowAnonymous="true"/>
</properties>
</profile>
</system.web>
csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html
5/59
7/4/13
Now add Global Application Class (Global.asax) by right clicking on solution explorer > add new
Item. and write code mentioned below in it.
01 void Profile_OnMigrateAnonymous(object sender,
ProfileMigrateEventArgs e)
02
{
03
ProfileCommon anonymousProfile =
Profile.GetProfile(e.AnonymousID);
04
if (anonymousProfile.SCart != null)
05
{
06
if (Profile.SCart == null)
07
Profile.SCart = new ShoppingCartExample.Cart();
08
09
Profile.SCart.Items.AddRange(anonymousProfile.SCart.Items
);
10
11
anonymousProfile.SCart = null;
12
}
13
14
ProfileManager.DeleteProfile(e.AnonymousID);
15
AnonymousIdentificationModule.ClearAnonymousIdentifier();
16
}
17
Add another webform and name it UserCart.aspx, in design view of this page drag the
CartControl we've just created and put a hyperlink for going back to products cataloge page
csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html
6/59
7/4/13
Tw eet
Like
Follow @dotnetfreak
We're on
Follow
csharpdotnetfreak.blogspot.com/2009/05/aspnet-creating-shopping-cart-example.html
7/59