On your description page you are creating a brand new array so you don't have anything but the last value as there is only one value that will be in your session.
try the following:
ArrayList idList = null;
if(Session["InstallationId"] != null)
idList = (ArrayList)Session["InstallationId"];
else
idList = new ArrayList();
This code checks to see if you already have an existing array in the session first, else it creates a new one.
You may want to try a different structure though for storing your data. A simpler one if you are doing product id, and product quantity is a NameValueCollection. It creates a name-value pair which would be useful here. That would avoid trying to figure out
which is the product id and which is the quantity. In this case, the Product Id would be a key that you can get values for, and the quantity would be the value.
// add items to the collection like so:
idList.Add(ProdID,ProQty);
To list all the items and values you can loop through the object to get both the key and the value
// example of a simple loop that lets you get a key, or a value based on an ordinal
for(int i = 0; i < idList.Count; i++)
{
// get a key value
idList.Keys[i];
// get a value
idList[i];
}
Don't forget to mark useful responses as Answer if they helped you towards a solution.
Marked as answer by weihan1394 on Jun 22, 2012 01:37 PM
markfitzme
Star
14471 Points
2236 Posts
Re: Add to Cart
Jun 22, 2012 01:23 PM|LINK
On your description page you are creating a brand new array so you don't have anything but the last value as there is only one value that will be in your session.
try the following:
ArrayList idList = null;
if(Session["InstallationId"] != null)
idList = (ArrayList)Session["InstallationId"];
else
idList = new ArrayList();
This code checks to see if you already have an existing array in the session first, else it creates a new one.
You may want to try a different structure though for storing your data. A simpler one if you are doing product id, and product quantity is a NameValueCollection. It creates a name-value pair which would be useful here. That would avoid trying to figure out which is the product id and which is the quantity. In this case, the Product Id would be a key that you can get values for, and the quantity would be the value.
NameValueCollection idList = null;
if(Session["idList"] != null)
idList = (NameValueCollection)idList;
else
idList = new NameValueCollection();
// add items to the collection like so:
idList.Add(ProdID,ProQty);
To list all the items and values you can loop through the object to get both the key and the value
// example of a simple loop that lets you get a key, or a value based on an ordinal
for(int i = 0; i < idList.Count; i++)
{
// get a key value
idList.Keys[i];
// get a value
idList[i];
}