c# - how to store multiple selected listbox items in a session and view on another form? -


The thing I want to do is select whether I want to select 1,2 or 3 items from listback and give them one Sessions and then display them all in a list box on another list.

This is my code! This is my first post on stack overflow, so please do not hate & lt; 3

  // WebForm1 Protected Zero Page_load (Object Sender, EventArgs e) {if (IsPostBack) {add lstProducts.Items ("Soap"); LstProducts.Items.Add ("Schampoo"); LstProducts.Items.Add ("conditioner"); }} Secure Zero cmdBuy_Click (Object Sender, EventArgs E) {string [] products = new string [3]; For (Int i = 0; I & lt; lstProducts.Items.Count; ++ i) {if (lstProducts.Items [i] selected) products [i] = lstProducts.Items [i]. Text; Other Products [i] = "0"; } Session ["cart"] = product; } Secure Zero cmdCart_Click (Object Sender, EventArgs E) {If (session ("cart") = null) {Response.Redirect ("WebForm2.aspx"); }}} // webform 2 protected void page_load (object sender, event cargo e) {string [] products = (string []) session ["cart"]; For (i.e. i = 0; i   

This is the thing that I only display the last selected item in the list box on form2 ???

Try it

To store all the items in the list box, you can add that item to the array: string [] A = new string [] {"item 1", "item 2", "item 3"}; session ["value"] = a;

and Next page In this case, you can retrieve it like this.

  string [] a = (string []) session ["value"]   

edit Do # 1

In your case, you can do this

  for ArrayList al = new ArrayList (); (Int I = 0; i   

Now you can use this cesium variable in any other page, but do not forget to put an Array link type object.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -