Ejemplo n.º 1
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            // Add members to GridView
            DataTable   Items;
            GridViewRow row       = null;
            bool        Duplicate = false;

            if (Session["ProjItems"] != null)
            {
                // Typecasting
                Items = (DataTable)Session["ProjItems"];

                foreach (GridViewRow r in GridView1.Rows)//AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa
                {
                    //if (r.Cells[3].Text.Trim().Equals(ComboBox1.Text))
                    if (ComboBox1.SelectedItem.Text.Trim().Equals(r.Cells[3].Text.Trim())) /*String.Equals(ComboBox1.Text, r.Cells[3].Text, StringComparison.InvariantCultureIgnoreCase)*/
                    {
                        //Items = (DataTable)Session["ProjItems"];
                        Duplicate = true;
                        row       = r;
                        break;//nooo d
                    }
                } //foreach END ---------AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

                if (Duplicate)
                {
                    string qty = (int.Parse(Items.Rows[row.RowIndex][0].ToString()) + int.Parse(TextBox10.Text)).ToString();
                    Items.Rows[row.RowIndex][0] = qty;
                    Items.AcceptChanges();
                }
                else
                {
                    DataRow ItemRow;
                    ItemRow                     = Items.NewRow();
                    ItemRow["QTY."]             = TextBox10.Text;
                    ItemRow["Item Code"]        = ComboBox1.SelectedItem.Text;
                    ItemRow["Item Description"] = ComboBox1.SelectedValue;

                    Items.Rows.Add(ItemRow);
                }
            }
            else
            {
                Items = new DataTable();
                Items.Columns.Add("QTY.");
                Items.Columns.Add("Item Code");
                Items.Columns.Add("Item Description");

                DataRow ItemRow;
                ItemRow                     = Items.NewRow();
                ItemRow["QTY."]             = TextBox10.Text;
                ItemRow["Item Code"]        = ComboBox1.SelectedItem.Text;
                ItemRow["Item Description"] = /*ComboBox1.SelectedValue;*/ Label11.Text;
                Items.Rows.Add(ItemRow);
            }


            GridView1.DataSource = Items;
            GridView1.DataBind();

            Session.Add("ProjItems", Items);
        }