Trying to understand transfering listbox values/items with sessions.

自作多情 提交于 2019-12-02 17:40:03

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!