Solved

asp.net web pages multidimensional session array

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

679 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