hey guys, I'm creating a basket for an e-commerce site, im trying to total up the basket values within the 'cart' class and return the value back to the 'basket' page where the total will be shown. The total is fine but i cant seam to return the total back to the 'basket' page.

heres my basket page:

protected void basketTotal()
        {           
            cart Cart = new cart(); //new instance of the cart
            string order = Session["orderid"].ToString(); //order_id from session
            int? total = 0;
           
            Cart.basketTotal(Session["orderid"].ToString(), total.ToString()); //passing order_id and total tothe cart class 
            Label1.Text = (Convert.ToString(total)); //return value will go here
        }

my cart class is as follows:

public string basketTotal(string order_id, string total)
        {
            using (api_basketDataContext apiTotal = new api_basketDataContext())
            {
                int orderid = (Convert.ToInt32(order_id));
                int? count = 0;

                var result3 = apiTotal.getBasketTotal
                                 (
                                 orderid,
                                 ref count
                                 );                
                
                foreach (var item in result3) //calculation of items
                {
                    var price = item.product_price;
                    var qty = item.quantity;
                    var subtotal = price * qty;

                    int i = 0;

                    if (i < count)
                    {
                      total = (Convert.ToString(total + subtotal));
                    }
                    i++;
                    
                }
                return (Convert.ToString(total)); 
            
            }
            
        }

the total is getting passed back to the parameters but this is not being passed back to the 'basket' page, is this even possible this way?

thanks.

ok, so after some more debugging the iv noticed that the values are getting returned, however they are getting reset back to the original value, therefore if total is returned as 300, it will reset back to 0 due to the "int? total = 0;". anyone have any ideas to why this is happening?

protected void basketTotal()
        {           
            cart Cart = new cart(); //new instance of the cart
            string order = Session["orderid"].ToString(); //order_id from session
            int? total = 0;
           
            Cart.basketTotal(Session["orderid"].ToString(), total.ToString()); //passing order_id and total tothe cart class 
            Label1.Text = (Convert.ToString(total)); //return value will go here
        }

thanks

Label1.Text =Cart.basketTotal(Session["orderid"].ToString(), total.ToString());

Thanks for the reply, after some research i discovered 'OUT' and used this.

Cart.basketTotal(order_id, out total, out counter, out items);
Label1.Text = "Total: £" + total.ToString();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.