Solved

asp.net web pages multidimensional session array

Posted on 2014-03-28
4
784 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 33

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 53

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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