Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2006, 05:56 PM
Authorized User
 
Join Date: Jul 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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");
    }
}


 
Old April 23rd, 2006, 01:37 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

what is CShoppingCartItem()?

 
Old April 24th, 2006, 08:46 PM
Authorized User
 
Join Date: Apr 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

a reference is missing.... You're usings only have System... references and CShoppingCartItem is in a different file/assembly






Similar Threads
Thread Thread Starter Forum Replies Last Post
shopping cart problem...! preetham.sarojavenkatesh Visual Studio 2005 1 November 13th, 2007 12:29 PM
Problem With Total in the Shopping Cart learningASP.Net BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 October 27th, 2007 09:33 AM
shopping cart problem Adam H-W Javascript 2 November 14th, 2006 12:57 PM
creating shopping cart saman General .NET 10 April 16th, 2004 03:10 PM
having problem with shopping cart radonfile Classic ASP Databases 0 September 26th, 2003 12:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.