protected void Button1_Click(object sender, EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { CheckBox cb = (CheckBox)row.FindControl("AprobarCheckBox"); Repositorio repo = new Repositorio(); DataSet dset = new DataSet(); dset.Tables.Add(); //agregamos una tabla al dataser dset.Tables[0].Rows.Add(); //se agrega una fila a la tabla creada dset.Tables[0].Columns.Add("id"); dset.Tables[0].Columns.Add("aprobado"); dset.Tables[0].Columns.Add("username"); dset.Tables[0].Rows[0]["id"] = GridView1.DataKeys[row.RowIndex].Values["id"].ToString(); if (cb.Checked) { dset.Tables[0].Rows[0]["aprobado"] = true; dset.Tables[0].Rows[0]["username"] = User.Identity.Name; repo.AprobarDesaprobarCasoInst(dset); } } GridView1.DataBind(); if (GridView1.Rows.Count == 0) Button1.Visible = false; else Button1.Visible = true; }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { Repositorio repo = new Repositorio(); DataSet dset = new DataSet(); dset.Tables.Add(); //agregamos una tabla al dataser dset.Tables[0].Rows.Add(); //se agrega una fila a la tabla creada dset.Tables[0].Columns.Add("id"); dset.Tables[0].Columns.Add("aprobado"); dset.Tables[0].Columns.Add("username"); if (e.CommandName == "Select") { // int intFila = Convert.ToInt32(e.CommandArgument.ToString()); //Obtener DataKey de la fila string idCaso = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument.ToString())].Values["id"].ToString(); //Dirigire a la página editar Response.Redirect("~/Hospital/InfoCaso.aspx?id=" + idCaso.Trim()); } else if (e.CommandName == "noaprobar") { // int intFila = Convert.ToInt32(e.CommandArgument.ToString()); //Obtener DataKey de la fila //string idCaso = GridView1.DataKeys[intFila].Value.ToString(); dset.Tables[0].Rows[0]["id"] = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument.ToString())].Values["id"].ToString(); dset.Tables[0].Rows[0]["aprobado"] = false; dset.Tables[0].Rows[0]["username"] = User.Identity.Name; repo.AprobarDesaprobarCasoInst(dset); GridView1.DataBind(); } else if (e.CommandName == "eliminar") { // int intFila = Convert.ToInt32(e.CommandArgument.ToString()); //Obtener DataKey de la fila string idCaso = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument.ToString())].Values["id"].ToString(); if (repo.EliminarCaso(idCaso, User.Identity.Name)) { } GridView1.DataBind(); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { //AprobarDesaprobarCasoInst Repositorio repo = new Repositorio(); DataSet dset = new DataSet(); dset.Tables.Add(); //agregamos una tabla al dataser dset.Tables[0].Rows.Add(); //se agrega una fila a la tabla creada dset.Tables[0].Columns.Add("id"); dset.Tables[0].Columns.Add("aprobado"); dset.Tables[0].Columns.Add("username"); dset.Tables[0].Rows[0]["id"] = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument.ToString())].Values["id"].ToString(); if (e.CommandName == "aprobar") { dset.Tables[0].Rows[0]["aprobado"] = true; dset.Tables[0].Rows[0]["username"] = User.Identity.Name; repo.AprobarDesaprobarCasoInst(dset); GridView1.DataBind(); } else if (e.CommandName == "noaprobar") { dset.Tables[0].Rows[0]["aprobado"] = false; dset.Tables[0].Rows[0]["username"] = User.Identity.Name; if (repo.AprobarDesaprobarCasoInst(dset)) { /* foreach (GridViewRow row in GridView1.Rows) { if (((CheckBox)row.FindControl("AprobarCheckBox")).Checked && !(GridView1.DataKeys[row.RowIndex].Values["id"].ToString() == GridView1.DataKeys[Convert.ToInt32(e.CommandArgument.ToString())].Values["id"].ToString())) cBoxSelections.Add( Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Values["id"].ToString()) ); }*/ } GridView1.DataBind(); if (cBoxSelections.Count != 0) foreach (int id in cBoxSelections) { foreach (GridViewRow row in GridView1.Rows) { if (GridView1.DataKeys[row.RowIndex].Values["id"].ToString() == id.ToString()) ((CheckBox)row.FindControl("AprobarCheckBox")).Checked = true; } } } else if (e.CommandName == "eliminar") { int intFila = Convert.ToInt32(e.CommandArgument.ToString()); //Obtener DataKey de la fila string idCaso = GridView1.DataKeys[intFila].Value.ToString(); if (repo.EliminarCaso(idCaso, User.Identity.Name)) { } GridView1.DataBind(); } else if (e.CommandName == "Select") { int intFila = Convert.ToInt32(e.CommandArgument.ToString()); //Obtener DataKey de la fila string idCaso = GridView1.DataKeys[intFila].Value.ToString(); //Dirigire a la página editar Response.Redirect("~/Hospital/InfoCaso.aspx?id=" + idCaso.Trim()); } if (GridView1.Rows.Count == 0) Button1.Visible = false; else Button1.Visible = true; }