protected void Page_Load(object sender, EventArgs e) { SqlConnection cn1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["strcon"].ConnectionString); SqlDataAdapter da = new SqlDataAdapter("select * from SANPHAM where ID = '" + Request.QueryString["id"] + "' ", cn1); DataSet ds = new DataSet(); da.Fill(ds, "Products"); DataList1.DataSource = ds.Tables["Products"]; DataList1.DataBind(); Random rnd = new Random(); String rndNum1 = rnd.Next(1, 19).ToString(); String rndNum2 = rnd.Next(24, 34).ToString(); SqlDataAdapter da2 = new SqlDataAdapter("select top 5 * from SANPHAM where ID between " + rndNum1 + " and " + rndNum2, cn1); DataSet ds2 = new DataSet(); da2.Fill(ds2, "Products"); DataList2.DataSource = ds2.Tables["Products"]; DataList2.DataBind(); if (!IsPostBack) { GioHangCS buy = new GioHangCS(); buy.CreateItem(); Session["buy"] = buy; } }
protected void Page_Load(object sender, EventArgs e) { bool check = true; if (!IsPostBack) { if (Request.QueryString["id"] != null) { SqlConnection cn1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["strcon"].ConnectionString); int id = int.Parse(Request.QueryString["id"].ToString()); String strcmd = "select * from SANPHAM where ID ='" + id.ToString() + "'"; SqlDataAdapter da1 = new SqlDataAdapter(strcmd, cn1); DataSet ds = new DataSet(); da1.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { string name = ds.Tables[0].Rows[0][2].ToString(); int gia = int.Parse(ds.Tables[0].Rows[0][6].ToString()); string hinh = ds.Tables[0].Rows[0][5].ToString(); int sl = 1; GioHangCS buy = new GioHangCS(); buy = (GioHangCS)Session["buy"]; buy.InsertProduct(id, name, hinh, gia, sl); Session["buy"] = buy; } check = false; } } GioHangCS fake = new GioHangCS(); GioHangCS buy1; fake.CreateItem(); DataTable t = fake.gioHang; Label1.Text = "0"; if (!check) { buy1 = (GioHangCS)Session["buy"]; t = buy1.gioHang; Label1.Text = buy1.TongTien().ToString(); } GridView1.DataSource = t; GridView1.DataBind(); }