protected void dgRol_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { if (e.NewSelectedIndex > -1) { subarea ob = sBll.GetById(Convert.ToInt32(dgSubarea.DataKeys[e.NewSelectedIndex].Value)); FillText(ob); } }
//METODOS //Salvar static public void Save(this subareaBLL s, subarea obj) { var x = ctx.subarea.Find(obj.id); if (x != null) { ctx.Entry(x).CurrentValues.SetValues(obj); } else { ctx.subarea.Add(obj); } ctx.SaveChanges(); }
//Buscar y cargar rol private void FillText(subarea ob = null, bool initial = false) { if (ob != null) { txtId.Text = ob.id.ToString(); txtNombre.Text = ob.nombre; cbxArea.SelectedValue = ob.idarea.ToString(); } else { txtId.Text = ""; txtNombre.Text = ""; cbxArea.SelectedIndex = 0; if (initial) { txtId.Text = ""; } } }
//Botón Buscar protected void btnBuscar_Click(object sender, EventArgs e) { try { if (txtId.Text.Trim() != "") { subarea obj = new subarea(); obj = sBll.GetById(Convert.ToInt32(txtId.Text)); FillText(obj); } else { FillText(); } } catch (Exception ex) { msgBox.InnerText = "Error: " + ex.Message; } }
//Boton Guardar protected void btnGuardar_Click(object sender, EventArgs e) { try { subarea obj = new subarea(); obj.nombre = txtNombre.Text; obj.idarea = Convert.ToInt32(cbxArea.SelectedValue); if (txtId.Text.Trim() != "") { obj.id = Convert.ToInt32(txtId.Text); } sBll.Save(obj); FillGrid(); msgBox.InnerText = ""; FillText(null, true); } catch (Exception ex) { msgBox.InnerText = "Error: " + ex.Message; } }