hi I'm using VS express for web and I'm using C#
I know how to replace value in arrraylist in java , but I found it hard to do it in c#
in the designe view in VS I have add button and textBox.. first I need to get what the user chose from the listBox and get the quantinty, but if the user chose the same product again , but with diffrenet quantity then the quantity in the output (lable) should change
this is the list of items
http://s3.postimage.org/gafmb5upv/list.png
and here is the outout http://s12.postimage.org/eqwr86ntp/output.png
here is my code

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

public partial class Menu_Order : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ArrayList ar = BuildItems();
            ArrayList temp = new ArrayList();
            foreach (Item it in ar)
            {
                ListItem li = new ListItem(it.Desc + "," + it.Price ,  it.ID.ToString());
                ListBox2.Items.Add(li);

            }
            //defualt value 
            ListBox2.SelectedIndex = 0;


            TextBox1.Text = "1";  

        }

    }   


    ArrayList BuildItems(){
        ArrayList temp  = new ArrayList();
        temp.Add(new Item (11, "Burger", 15));
        temp.Add(new Item(12, "Cheese Burger", 20));
        temp.Add(new Item(13, "Kebab", 24));
        temp.Add(new Item(20, "Chiken Schawerma", 18));
        temp.Add(new Item(22, "Beef Schawerma", 20));
        temp.Add(new Item(35, "Grilled Chiken", 25));
        temp.Add(new Item(34, "Grilled Fish", 22));
        temp.Add(new Item(40, "Big Pizza", 18));
        temp.Add(new Item(42, "Small Pizza", 14));
        temp.Add(new Item(50, "Falafel", 10));

        return temp;
        }
    void DisplayList(ArrayList temp)
    {
        Label1.Text = "<table>";
        Label1.Text = Label1.Text + "<tr><td>" + "ID"
       + "</td><td>" + "Description" + "</td><td>" + "Price" + "</td><td>" + "Quantity" + "</td><td>" + "Amount" + "</td></tr>";
        foreach (OrderedItem s in temp)
        {

    Label1.Text = Label1.Text + "<tr><td>" + s.ID+ "</td><td>" + s.Desc + "</td><td>" + s.Price + "</td><td>" + s.Qt +"</td><td>"+ s.Qt * s.Price + "</td></tr>"; 
        }
        Label1.Text = Label1.Text + "</table>";


    }



    protected void Button1_Click1(object sender, EventArgs e)
    {
     string choice = ListBox2.SelectedItem.Text;
        string [] p = choice.Split(',');
        string des = p[0];
        int price = int.Parse(p[1]);
        int id = int.Parse(ListBox2.SelectedValue); 
        int qt = int.Parse(TextBox1.Text);
        OrderedItem a = new OrderedItem(id, des, qt, price);
        ArrayList savedItem = new ArrayList();


        if (Session["items"] != null)
        {       
            savedItem = (ArrayList)Session["items"];
         }
        savedItem.Add(a);
        Session["items"] = savedItem;
              DisplayList(savedItem);
              }
              } 

Also List can be used. List<Item> tempLst = new List<Item>();
See here
Use IndexOf,RemoveAt, Insert methods to get wath you want.

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.