protected void grvNhomChucDanh_DeleteCommand(object sender, GridCommandEventArgs e) { switch (e.Item.OwnerTableView.Name) { case "tbl_NhomChucDanh": var iDNhomChucDanh = (e.Item as GridDataItem).GetDataKeyValue("IDNhomChucDanh").ToString(); int id = Convert.ToInt32(iDNhomChucDanh); _entities.DeleteChucDanhChuyenMonByIDNhomChucDanh(id); _entities.SaveChanges(); break; case "tbl_ChucDanhChuyenMon": var iDChucDanhChuyenMon = (e.Item as GridDataItem).GetDataKeyValue("IDChucDanh").ToString(); int idcm = Convert.ToInt32(iDChucDanhChuyenMon); ChucDanh chucdanh = _entities.ChucDanhs.Where(d => d.IDChucDanh == idcm).First(); _entities.ChucDanhs.DeleteObject(chucdanh); _entities.SaveChanges(); break; } }