Ok so my problem is everytime I click my button it re-populates my dropdownlist of my entries, but it also keeps the entries from my previous page_load therefore i get double entries within my dropdownlist. How do I solve this problem as I cannot seem to find where my problem is:

Code can be seen below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PartD
{
    public partial class About : Page
    {
        List<Beverage> account;
        string[] arr;
        protected void Page_Load(object sender, EventArgs e)
        {


            arr = (string[])Session["arr"];
            for (int i = 0; i < arr.Length; i++)
            {
                DropDownList1.Items.Add(arr[i].ToString());
            }

            if (Session["bubble"] == null)
            {
                account = new List<Beverage>();
                Session["bubble"] = account;
            }
            else
            {
                account = (List<Beverage>)Session["bubble"];
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ListBox1.Items.Clear(); // clears ListBox1
            Beverage f = new Beverage(DropDownList1.Text, int.Parse(TextBox1.Text),
       int.Parse(TextBox2.Text), CheckBox1.Checked); // gets text from textbox5, then converts textbox2,textbox3 string to int and will execute of checkbox1 is checked
            account = (List<Beverage>)Session["bubble"]; // displays results in listbox1
            account.Add(f); // adds items to listbox
            foreach (var item in account)
            {
                ListBox1.Items.Add(item.getFruitInfo());
            }
        }
    }
}

Fixed my problem by using the following:

if (!Page.IsPostBack)
            {
                arr = (string[])Session["arr"];
                for (int i = 0; i < arr.Length; i++)
                {
                    DropDownList1.Items.Add(arr[i].ToString());
                }

            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.