protected void BtnAgregarPlaga_Click(object sender, EventArgs e) { //************ if (GV_PlagaMaEnf.Rows.Count > 0) { foreach (GridViewRow row in GV_PlagaMaEnf.Rows) { string valorcol2 = row.Cells[1].Text; if (row.Cells[1].Text == txt_Plagas.Text.Trim()) { string script = @"<script type='text/javascript'>alert('{0}');</script>"; script = string.Format(script, "PLAGA YA REGISTRADA..!"); ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false); return; } } } //************ if (ViewState["dtPME"] != null) { DataTable dtTable = (DataTable)ViewState["dtPME"]; DataRow drRow = null; if (dtTable.Rows.Count > 0) { //if (dtTable.Rows[0]["Detalle"].ToString() == "Plaga "+txt_Plagas.Text.Trim()) //{ // string script = @"<script type='text/javascript'>alert('{0}');</script>"; // script = string.Format(script, "PLAGA YA REGISTRADA..!"); // ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false); // return; //} drRow = dtTable.NewRow(); drRow["PME"] = "PLAGA"; drRow["Detalle"] = txt_Plagas.Text.Trim(); drRow["Intensidad"] = DDLIntensidad_Plaga.SelectedValue.ToString(); drRow["Tratamiento"] = txt_Tratamiento_Plagas.Text.Trim(); } if (dtTable.Rows[0][0].ToString() == "") { dtTable.Rows[0].Delete(); dtTable.AcceptChanges(); } dtTable.Rows.Add(drRow); ViewState["dtPME"] = dtTable; GV_PlagaMaEnf.DataSource = dtTable; GV_PlagaMaEnf.DataBind(); Limpiar_CAMPOS_PLAGA(); } }
protected void GV_PlagaMaEnf_RowDeleting(object sender, GridViewDeleteEventArgs e) { int index = Convert.ToInt32(e.RowIndex); DataTable dt = ViewState["dtPME"] as DataTable; dt.Rows[index].Delete(); ViewState["dtPME"] = dt; GV_PlagaMaEnf.DataSource = ViewState["dtPME"] as DataTable; GV_PlagaMaEnf.DataBind(); Limpiar_CAMPOS_PLAGA(); Limpiar_CAMPOS_MALEZA(); Limpiar_CAMPOS_ENFERMEDADES(); if (dt.Rows.Count == 0) { DataRow dr; dr = dt.NewRow(); dt.Rows.Add(dr); GV_PlagaMaEnf.DataSource = dt; GV_PlagaMaEnf.DataBind(); } }
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { if (RadioButtonList1.SelectedItem.Text == "SI") { pnlPlaga.Visible = true; DataTable dtPME = new DataTable(); DataRow drPME; dtPME.TableName = "PME"; dtPME.Columns.Add(new DataColumn("PME", typeof(string))); dtPME.Columns.Add(new DataColumn("Detalle", typeof(string))); dtPME.Columns.Add(new DataColumn("Intensidad", typeof(string))); dtPME.Columns.Add(new DataColumn("Tratamiento", typeof(string))); drPME = dtPME.NewRow(); dtPME.Rows.Add(drPME); ViewState["dtPME"] = dtPME; GV_PlagaMaEnf.DataSource = dtPME; GV_PlagaMaEnf.DataBind(); } else { DataTable dtTable = (DataTable)ViewState["dtPME"]; if (dtTable.Rows[0][0].ToString() == "") { DataTable dtAdversidad = new DataTable(); ViewState["dtPME"] = dtAdversidad; Limpiar_CAMPOS_PLAGA(); Limpiar_CAMPOS_MALEZA(); Limpiar_CAMPOS_ENFERMEDADES(); pnlPlaga.Visible = false; } else { string script = @"<script type='text/javascript'>alert('{0}');</script>"; script = string.Format(script, "EXISTEN DATOS REGISTRADOS..!"); ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, false); } } }