protected void ButtonDelete33_Command(object sender, CommandEventArgs e) { string sId = (string)e.CommandArgument; int iid = Convert.ToInt32(sId); if (db == null) { db = new GoodContext(); } good = this.db.Goods.Find(iid); if (good != null) { db.Goods.Remove(good); db.SaveChanges(); ListView2.DataBind(); return; } }
protected void Save(object sender, CommandEventArgs e) { string err; string vName, vPrice; decimal dPrice; //string sId = (string)e.CommandArgument; string sId = goodID.Value; //Во избежании if (sId == "-1") return; ChkDataOnServer(out err); if (err != "") { ShowError(err); return; } int iid = Convert.ToInt32(sId); vName = txtName.Text; vPrice = txtPrice.Text.Replace(".", ","); dPrice = decimal.Parse(vPrice); if (db == null) { db = new GoodContext(); } if (iid == 0) //Вставка { this.good = new Good(); } else // Редактирование { this.good = this.db.Goods.Find(iid); } this.good.Name = vName; this.good.Price = dPrice; if (good != null) { if (iid == 0) //Вставка db.Goods.Add(good); db.SaveChanges(); //if (iid == 0) goodID.Value = "-1"; //return RedirectToAction("Index"); ; UpdatePanel1.Update(); ListView2.DataBind(); return; } }