protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Session["MyCart"] != null) { Cart.DataSource = ((DataTable)(Session["MyCart"])).DefaultView; Cart.DataBind(); Cart.Items[0].Visible = false; } else { Response.Redirect("Products.aspx"); } } } protected void Cart_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "UpdateCart") { string Pid = e.CommandArgument.ToString(); TextBox txtquantity = (TextBox)e.Item.FindControl("txtQuantity"); DataTable dt = new DataTable(); dt = (DataTable)(Session["MyCart"]); //// Get all DataRows where the name is the name you want. IEnumerable<DataRow> rows = dt.Rows.Cast<DataRow>().Where(r => r["Pid"].ToString() == Pid); //// Loop through the rows and change the name. rows.ToList().ForEach(r => r.SetField("Quantity", int.Parse(txtquantity.Text))); Session["MyCart"] = dt; Cart.DataSource = ((DataTable)(Session["MyCart"])).DefaultView; Cart.DataBind(); Cart.Items[0].Visible = false; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)