在页面重新加载上,“转到购物车”按钮不可见

时间:2016-09-02 07:05:52

标签: c# asp.net e-commerce 3-tier

我想在将产品添加到购物车后制作一个按钮Go To Cart可见。但是当页面重新加载时,它只显示“添加到购物车”按钮

/ 这是我的表示层代码 /

    protected void ddlimginfo_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName=="addtocart")
            {
                Label price = e.Item.FindControl("lblprice") as Label;
                string prc = price.Text;
                DateTime pdate = Convert.ToDateTime(System.DateTime.Now);
                string postdate = (pdate.ToString("yyyy-mm-dd", CultureInfo.InvariantCulture));
                Button btnaddcart = e.Item.FindControl("btnaddcart") as Button;
                Button btngocart = e.Item.FindControl("btngocart") as Button;

                //balobj.dalCart((Session["uip"]).ToString(), Convert.ToInt32(Sessio

n["id"]), qty, prc,pdate);
            //DateTime existingDate =Convert.ToDateTime(balobj.getdate((Session["uip"]).ToString()));
            //string exdate = (existingDate.ToString("yyyy-mm-dd", CultureInfo.InvariantCulture));
            balobj.dalCart(Convert.ToString(Session["uip"]), Convert.ToInt32(Session["id"]), 1, prc, pdate);
            if ((Session["uip"]) != null)
            {

                Session["count"] = balobj.cartcount((Session["uip"]).ToString());
                DataTable dt = new DataTable();
                dt = balobj.balgocart(Convert.ToString(Session["uip"]), Convert.ToInt32(Session["id"]));

                if (dt.Rows.Count > 0)
                {

                    //Session["count"] = balobj.cartcount((Session["uip"]).ToString());
                    btnaddcart.Visible = false;
                    btngocart.Visible = true;
                    Response.Redirect("infoproduct.aspx");

                }
                else
                {

                    //Session["count"] = balobj.cartcount((Session["uip"]).ToString());
                    btnaddcart.Visible = true;
                    btngocart.Visible = false;
                    Response.Redirect("infoproduct.aspx");

                }
                //Response.Write(Session["count"]);
                //Response.End();
                //Response.Redirect("infoproduct.aspx");
            }

/ 这是我的BAL代码 /

//Go to cart button visible
        public DataTable balgocart(string uip, int proid)
        {

            try
            {
                return dalobj.dalgocart(uip, proid);
            }
            catch
            {
                throw;
            }
            finally
            {
                dalobj = null;
            }

        }

/ 这是我的DAL代码 /

//Code to visible button go to cart
        public DataTable dalgocart(string uip, int proid)
        {

            MySqlConnection con = new MySqlConnection(str);

            try
            {
                con.Open();
                MySqlCommand cmd = new MySqlCommand("spbtngocart", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("spuip", uip);
                cmd.Parameters.AddWithValue("spproid", proid);

                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;


            }
            catch (Exception ex)
            {

                throw ex;

            }
            finally
            {
                con.Close();
            }

        }

1 个答案:

答案 0 :(得分:1)

您需要在进行更改后重新绑定控件

DataList1.DataBind();