Solved

asp.net web pages multidimensional session array

Posted on 2014-03-28
4
752 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 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 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 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