protected void QuitarBeneficiarios(object sender, EventArgs e) { DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("IdPersona", typeof(string))); dt.Columns.Add(new DataColumn("Nombre", typeof(string))); foreach (GridViewRow row in BeneficiariosGridView.Rows) { dr = dt.NewRow(); dr["IdPersona"] = row.Cells[0].Text.ToString(); dr["Nombre"] = row.Cells[1].Text.ToString(); dt.Rows.Add(dr); } foreach (GridViewRow row in BeneficiariosGridView.Rows) { //busca el la fila if (row.RowType == DataControlRowType.DataRow) { //si esta checkeado instancia las propiedades del objeto CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox); if (chkRow.Checked) { dt.Rows[row.RowIndex].Delete(); } } } BeneficiariosGridView.DataSource = dt; BeneficiariosGridView.DataBind(); }
protected void CargaBeneficiarios(object sender, EventArgs e) { if (txtbenefiario.Value != string.Empty) { DataTable dt = new DataTable(); DataRow dr = null; string nombre; dt.Columns.Add(new DataColumn("IdPersona", typeof(string))); dt.Columns.Add(new DataColumn("Nombre", typeof(string))); if (BeneficiariosGridView.Rows.Count > 0) { if (BeneficiariosGridView.Rows.Count >= 4) { Response.Write("<script>window.alert('No puede exceder el maximo de 4 beneficiarios');</script>"); //this.mensajeError.InnerHtml = "No puede exceder el maximo de 4 beneficiarios"; } foreach (GridViewRow row in BeneficiariosGridView.Rows) { dr = dt.NewRow(); dr["IdPersona"] = row.Cells[0].Text.ToString(); dr["Nombre"] = row.Cells[1].Text.ToString(); dt.Rows.Add(dr); } } nombre = returnaNombre(txtbenefiario.Value); if (nombre == string.Empty) { Response.Write("<script>window.alert('Beneficiario no se encuentra registrado en Personas');</script>"); //this.mensajeError.InnerHtml = "Beneficiario no se encuentra registrado en Personas"; this.txtbenefiario.Value = string.Empty; } else { if (BeneficiariosGridView.Rows.Count != 4) { dr = dt.NewRow(); dr["IdPersona"] = txtbenefiario.Value; dr["Nombre"] = nombre; dt.Rows.Add(dr); BeneficiariosGridView.DataSource = dt; BeneficiariosGridView.DataBind(); this.txtbenefiario.Value = string.Empty; } } } else { Response.Write("<script>window.alert('Debe Ingresar el numero de cedula del Beneficiario');</script>"); //this.mensajeError.InnerHtml = "Debe Ingresar el numero de cedula del Beneficiario"; } }