Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string        strcn = ConfigurationManager.ConnectionStrings["BTL_Web"].ToString();
        SqlConnection cn    = new SqlConnection(strcn);

        SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM DanPiano", cn);
        DataSet        ds = new DataSet();

        da.Fill(ds, "abc");
        DataList1.DataSource = ds.Tables["abc"];
        DataList1.DataBind();
        if (!IsPostBack)
        {
            XayDung cart = new XayDung();
            cart.craeteItem();
            Session["Cart"] = cart;
        }
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["cart"] != null)
            {
                int id = int.Parse(Request.QueryString["id"].ToString() + "");

                String         strcmd = "select * from DanPiano where MaDan ='" + id.ToString() + "'";
                SqlDataAdapter da1    = new SqlDataAdapter(strcmd, cn1);
                DataSet        d      = new DataSet();
                da1.Fill(d);
                if (d.Tables[0].Rows.Count > 0)
                {
                    string  name    = d.Tables[0].Rows[0][1].ToString();
                    int     dongia  = int.Parse(d.Tables[0].Rows[0][2].ToString());
                    string  hinhanh = d.Tables[0].Rows[0][3].ToString();
                    int     sl      = 1;
                    XayDung cart    = new XayDung();
                    cart = (XayDung)Session["Cart"];
                    cart.insertProduct(id, name, sl, dongia, hinhanh);
                    Session["Cart"] = cart;
                }
            }
            else
            {
                Response.Redirect("GioHang2.aspx");
            }
        }
        //hiển thị giỏ hàng
        XayDung   cart1 = (XayDung)Session["Cart"];
        DataTable t     = cart1.gioHang;

        GridView1.DataSource = t;
        GridView1.DataBind();
        lblbKetqua.Text = cart1.TongTien().ToString();
    }