protected void BtnSalvar_Click(object sender, EventArgs e) { Model.Squad squad = getData(); var db = new SquadDB(); if ((IdH.Value == "0") || (IdH.Value == "")) { if (db.Insert(squad)) { LblMsg.Text = "Registro inserido!"; LoadGrid(); } else { LblMsg.Text = "Erro ao inserir registro"; } } else { if (db.Update(squad, int.Parse(IdH.Value))) { LblMsg.Text = "Registro atualizado!"; } else { LblMsg.Text = "Erro ao atualizar registro"; } } LoadGrid(); }
protected void GVSquad_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = GVSquad.Rows[index]; int id = Convert.ToInt32(row.Cells[0].Text); var db = new SquadDB(); if (e.CommandName == "Excluir") { db.Delete(id); LoadGrid(); } else if (e.CommandName == "Editar") { Model.Squad squad = db.SelectById(id); TxtNome.Text = squad.Nome; TxtQtdPessoas.Text = squad.QtdPessoas.ToString(); IdH.Value = squad.Id.ToString(); } }