在“页面重新加载”中,“转到目录”;按钮不可见

本文关键字:转到目录 按钮 新加载 加载 | 更新日期: 2023-09-27 18:05:31

我想在添加产品到购物车后使按钮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();
            }
        }

在“页面重新加载”中,“转到目录”;按钮不可见

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

DataList1.DataBind();