I'm creating a shopping cart application and I'm having some issues with implementing a session state for my arraylist.
in my page load i declared
if (Session["Cart"] == null)
{
Session["Cart"] = new ArrayList();
}
else
{
ArrayList cart = (ArrayList)Session["Cart"];
}
to create the session if it doesn't exist yet. then i have an event handler for a button to add items to t开发者_StackOverflow中文版he arraylist
protected void onClick_AddBooking(object sender, EventArgs e)
{
int ClassID = Convert.ToInt32(Request.QueryString.Get("Class_Id"));
ArrayList cart1 = new ArrayList();
cart1 = Session["Cart"];
cart1.Add(ClassID);
i'm guessing i just don't know how to handle session states yet, thus the confusion. I'm essentially storing the class_ID then when the student confirms i'll store that to the DB and associate that ID with the Class Details.
Thanks in advance guys!
Is there a problem you are having? Try the following:
protected void onClick_AddBooking(object sender, EventArgs e)
{
int ClassID = Convert.ToInt32(Request.QueryString.Get("Class_Id"));
ArrayList cart1 = new ArrayList();
cart1 = (ArrayList)Session["Cart"];
cart1.Add(ClassID);
Session["Cart"] = cart1;
Make a class where you define the properties productName
, productQty
, productPrice
then make the object of that class and add the values in these properties.
Then add that object into the ArrayList
and save that ArrayList
again in the session.
精彩评论