protected void Button1_Click1(object sender, EventArgs e) { int maSP = Int32.Parse(Request.QueryString["maSP"].ToString()); int SoLuongMua = int.Parse(txtSoLuong.Text); if (Session["giohang"] == null) { Session["giohang"] = new List <GioHangDetailDTO>(); } List <GioHangDetailDTO> giohang = Session["giohang"] as List <GioHangDetailDTO>; if (giohang.FirstOrDefault(m => m.ID == maSP) == null) { DataTable dt = lop_son.TimSP("Select * from SanPham where maSP='" + maSP + "'"); GioHangDetailDTO newItem = new GioHangDetailDTO(int.Parse(dt.Rows[0]["maSP"].ToString()), dt.Rows[0]["tenSP"].ToString(), dt.Rows[0]["hinhAnh"].ToString(), SoLuongMua , double.Parse(dt.Rows[0]["gia"].ToString())); giohang.Add(newItem); Session["giohang"] = giohang; } else { foreach (GioHangDetailDTO item in giohang) { if (item.ID == maSP) { item.SoLuong++; } } Session["giohang"] = giohang; } Response.Redirect("GioHang.aspx"); }