Problem Creating Shopping Cart Object
Hello and thank you for taking a moment. I am building a product catalog/Shopping Cart application using C#. I am usng session variables and arrays to do so. Whenever I go to create the shopping cart object with the following line of code:
CShoppingCartItem item = new CShoppingCartItem();
Visual Studio throws me this error:
The type or namespace name 'CShoppingCartItem' could not be found (are you missing a using directive or an assembly reference?)
I was wondering if anybody could tell me what is causing the error.Below is my complete code behind. Any help would be greatly appreciated.
Thank You,
Jason
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class productcatalog : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["NWind"] = System.Configuration.ConfigurationManager.AppSetti ngs["NWind"].ToString();
if (!Page.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
SqlConnection oSQLConn = new SqlConnection(Session["NWind"].ToString());
oSQLConn.Open();
SqlDataAdapter da =
new SqlDataAdapter
("select * from products", oSQLConn);
DataSet ds = new DataSet();
da.Fill(ds, "products");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexCh anged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ArrayList arr;
if (Session["mycart"] != null)
{
arr = (ArrayList)Session["mycart"];
}
else
{
arr = new ArrayList();
Session["mycart"] = arr;
}
CShoppingCartItem item = new CShoppingCartItem();
item.ProductID = int.Parse(DataGrid1.SelectedItem.Cells[1].Text);
item.ProductName = DataGrid1.SelectedItem.Cells[2].Text;
item.UnitPrice = decimal.Parse(DataGrid1.SelectedItem.Cells[3].Text);
item.Quantity = 1;
arr.Add(item);
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("cart.aspx");
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class productcatalog : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["NWind"] = System.Configuration.ConfigurationManager.AppSetti ngs["NWind"].ToString();
if (!Page.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
SqlConnection oSQLConn = new SqlConnection(Session["NWind"].ToString());
oSQLConn.Open();
SqlDataAdapter da =
new SqlDataAdapter
("select * from products", oSQLConn);
DataSet ds = new DataSet();
da.Fill(ds, "products");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexCh anged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ArrayList arr;
if (Session["mycart"] != null)
{
arr = (ArrayList)Session["mycart"];
}
else
{
arr = new ArrayList();
Session["mycart"] = arr;
}
CShoppingCartItem item = new CShoppingCartItem();
item.ProductID = int.Parse(DataGrid1.SelectedItem.Cells[1].Text);
item.ProductName = DataGrid1.SelectedItem.Cells[2].Text;
item.UnitPrice = decimal.Parse(DataGrid1.SelectedItem.Cells[3].Text);
item.Quantity = 1;
arr.Add(item);
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("cart.aspx");
}
}
|