On my first page I have two listboxes for Movies and Snacks
They are called lbDisplay for Movies and lbSelected for Snacks.
I am currently using a "Go to cart" function that has the following code:
Session["lbSelectedMovies"] = lbDisplay;
Session["lbSelectedSnacks"] = lbSelected;
Response.Redirect("RingU6POSReview.aspx");
on the redirected page the two listboxes that I want the given values to transfer to are called lbRvMovies and lbRvSnacks
The page is called RingU6POSReview.aspx
Can anyone help me understand how to transfer the values when I redirect the customer?
On the 2nd page say you have another list box (say ListBox1) to which you want to assign the passed values then use the any one of the foll. 3 methods:
ListBox ListBox1 = null;
ListBox1 = Session["lbSelectedMovies"] as ListBox;
OR
ListBox ListBox1 = new ListBox();
foreach (ListItem Item in ((ListBox)(Session["lbSelectedMovies"])).Items)
{
ListBox1.Items.Add(new ListItem(Item.Text, Item.Value));
}
OR
ListBox1.Items.AddRange((ListItem[])Session["lbSelectedMovies"]);
来源:https://stackoverflow.com/questions/22474880/trying-to-understand-transfering-listbox-values-items-with-sessions