0

在会话对象中存储值是否正确

我试过了,但没有正常工作。我的意思是,存储在会话中的值无法正确访问或存储。谁能帮我解决这个问题?谢谢你。

 protected void Page_Load(object sender, EventArgs e)
        {       
            if (!IsPostBack)
            {            
                if (Session["cart_table"] == null)
                {
                    DataTable dt = new Spcart().GetCart();
                    Session["cart_table"] = dt;                 
                }

                if (Session["ptax"] == null)
                {
                    Session["ptax"] = 0;
                }
                if (Session["subtotal"] == null)
                {
                    Session["subtotal"] = 0;
                }

                  BindCartListView();
              }
         }

 public void BindCartListView()
    {
        -----------------------              //some code 

        int tax=100;
        int total=300;
        int[] totals;
        totals = bindtotal(tax, total); 

        -----------------------------------     //some code 
    }

 public int[] bindtotal(int tax, int total)
    {

        int ptax = (int)Session["ptax"];
        ptax += tax;
        Session["ptax"] = ptax;

        int subtotal = (int)Session["subtotal"];
        subtotal += total;
        Session["ptax"] = subtotal;

        int granttotal = ptax + subtotal;
        Session["granttotal"] = granttotal;

        int[] totals = { subtotal, granttotal };
        return totals;
    }       
4

1 回答 1

0

是的,它似乎是正确的,但如果它给出任何错误,那么请发布那个错误..否则它看起来没问题

于 2012-10-22T11:33:54.833 回答