Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net c# using session data to output more data
    primarykey
    data
    text
    <p>Ok guy, i have made a simple program that has a web form where you fill in details fruit name, kg and cal count. i have then used session variables to get the fruit name from the form on default page and display them on about page in a drop down menu. that's all working fine, what i cant seem to work out is on the about page how to get it so the user selects a item from the drop down (created from form on default page) then enter a int how many they want (in text box) and have there selection and amount output on a list box on about page. il post the code i have so far any help would be much appreciated.</p> <p><strong>default page</strong></p> <pre><code> public class Fruit { private string fName; private int grams, calsPerGram; private bool edible; public Fruit(string n, int g, int c, bool e) { grams = g; calsPerGram = c; edible = e; fName = n; } public int totalCalories() { return grams * calsPerGram; } public string getFruitInfo() { string s; if (edible == true) { s = fName + " is yummy and it has " + totalCalories() + "calories"; } else { s = "Hands off! Not edible"; } return s; } } public partial class _Default : System.Web.UI.Page { List&lt;Fruit&gt; myBasket; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { myBasket = new List&lt;Fruit&gt;(); Session["listSession"] = myBasket;// seassion start } } protected void Button1_Click1(object sender, EventArgs e) { // Session["Fruitname"] = TbxName.Text; // my session i have made MyFruit = Session["Fruitname"] as List&lt;string&gt;; //Create new, if null if (MyFruit == null) MyFruit = new List&lt;string&gt;(); MyFruit.Add(TbxName.Text); Session["Fruitname"] = MyFruit; abc.Items.Clear(); Fruit f = new Fruit(TbxName.Text, int.Parse(TbxWeight.Text), int.Parse(TbxCal.Text), CheckBox1.Checked); myBasket = (List&lt;Fruit&gt;)Session["listSession"]; // session used myBasket.Add(f); foreach (var item in myBasket) { abc.Items.Add(item.getFruitInfo()); // List box used } } public List&lt;string&gt; MyFruit { get; set; } } </code></pre> <p><strong>About page</strong></p> <pre><code>public partial class About : Page { protected void Page_Load(object sender, EventArgs e) { MyFruit = Session["Fruitname"] as List&lt;string&gt;; //Create new, if null if (MyFruit == null) MyFruit = new List&lt;string&gt;(); DropDownList1.DataSource = MyFruit; DropDownList1.DataBind(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Drinklabel.Text = "Your Chosen Beverage is A " + DropDownList1.SelectedValue.ToString() + " Drink."; } public List&lt;string&gt; MyFruit { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload