protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { if (Page.IsValid) { if (CoQuanBH == null) { VBPQ_CoQuanBH vc = new VBPQ_CoQuanBH(); vc.TenCoQuanBH = txtCQBH.Text; vc.GhiChu = txtGhiChu.Text; db.VBPQ_CoQuanBHs.InsertOnSubmit(vc); db.SubmitChanges(); } else { CoQuanBH.TenCoQuanBH = txtCQBH.Text; CoQuanBH.GhiChu = txtGhiChu.Text; db.SubmitChanges(); } Response.Redirect(Common.GenerateAdminUrl("vbpq_cqbh")); } } }
protected void grvCQBH_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = Convert.ToInt32(grvCQBH.DataKeys[e.RowIndex].Value); VBPQ_CoQuanBH vCate = db.VBPQ_CoQuanBHs.SingleOrDefault <VBPQ_CoQuanBH>(vc => vc.Id == id); if (vCate != null) { db.VBPQ_CoQuanBHs.DeleteOnSubmit(vCate); db.SubmitChanges(); LoadData(); } }