Solved

asp.net web pages multidimensional session array

Posted on 2014-03-28
4
730 Views
Last Modified: 2014-03-28
Hello,

What I would like to do is store shopping cart items into session and store them in session array as such:

 
Session["cart"]
[0] => "1234"         - ItemID
          => "1"           - Qty
          => "10.00"    - Price
[1] => "1168"
          => "2"
          => "20.00"

Open in new window

0
Comment
Question by:CEL_IT
4 Comments
 
LVL 32

Accepted Solution

by:
Big Monty earned 250 total points
ID: 39961691
not sure if you're looking for a .NET solution or classic asp solution (since that's what you put the question in). I'm assuming .NET, so try this below:

string[,] myArray = new string[,] { { "1234", "1", "10.00" }, { "1168", "2", "20.00" };
Session("cart") = myArray;
0
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 250 total points
ID: 39961780
Just as easy as storing the array in the session, you can store in a cookie.  One of the problems with sessions is if the worker process over loads for some reason, the session restarts.  I have run into that before, it is not common, but does happen.  

On a slight tangent, it is best for your cart to store just the item_id and qty.  The price should be by a database look up and especially when submitting the final payment form.  Only submit item_id and qty and let the back end figure out the correct price, discount etc so you don't get spoofed.
0
 

Author Comment

by:CEL_IT
ID: 39961840
thanks Big monty,

Additionally, To retrieve from session:

var cartItems = (string[,])HttpContext.Current.Session["cart"];

Open in new window


To Count rows or columns:

int rows = cartItems .GetLength(0); 
int cols = cartItems .GetLength(1); 

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now