Using UpdatePanel or any other method to save dynamic rows
I have been searching the site for a good answer to this type of problem but everyone has a different way of solving this plus my english has been a bit lackluster regarding documentation:
https://msdn.microsoft.com/en-us/library/bb399001.aspx
I tried using Session variable to cast the Table OnPostBack but it does not work anyway:
My HTML Code (reduced) is:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="popup.aspx.cs" Inherits="AgroRiego.popup" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Horario</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<form id="form1" runat="server">
<div class="container mb-5">
<div class="row">
<div class="offset-4 col-4">
<asp:DropDownList ID="select_predo" AutoPostBack="true" runat="server" CssClass="form-control"></asp:DropDownList>
</div>
</div>
</div>
<div class="container">
<asp:Table ID="riego" ViewStateMode="Enabled" runat="server" CssClass="container">
<asp:TableHeaderRow CssClass="row">
<asp:TableHeaderCell CssClass="col" Enabled="false">Múltiplo</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Dia programado</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col" Enabled="false">Horario</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Cantidad de Horas</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Horario término</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Fertilización</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</div>
<div class="container">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Table ID="fertilizacion" EnableViewState="true" Visible="false" runat="server" CssClass="container">
<asp:TableHeaderRow CssClass="row">
<asp:TableHeaderCell CssClass="col">Horas de Fertilización</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Hora de Inicio</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Producto</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Unidad</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Hectareas</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Has</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Mult</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Basically, i add rows dinamically on the first table with a button that OnClick adds a row to the second table, problem is the table only saves the last row added! and i still don't understand why it does not save the previous iteration, if someone gives me an answer with a thorough explanation i'd love him till the ends of my days.
Server side code:
public partial class popup : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable predos = Session["predos"] as DataTable;
if (!IsPostBack)
{
foreach (DataRow row in predos.Rows)
select_predo.Items.Add(row["ID"].ToString());
Deploy(predos.Rows[0]["ID"].ToString());
}
else
{
Deploy(select_predo.SelectedValue);
}
}
public void Deploy(string first_let)
{
DataTable taba = Session[0] as DataTable;
foreach (DataRow row in taba.Rows)
{
if (row["Multiplo"].ToString().Contains(first_let))
{
TableRow r = new TableRow();
r.ID = row["Multiplo"].ToString();
r.CssClass = "row";
TableCell sector = new TableCell();
sector.CssClass = "col";
sector.Text = row["Multiplo"].ToString();
r.Cells.Add(sector);
TableCell dia = new TableCell();
dia.CssClass = "col";
dia.Text = DateTime.Parse(row["Fecha"] as string).ToShortDateString();
r.Cells.Add(dia);
TableCell hora = new TableCell();
hora.CssClass = "col";
DropDownList horas = new DropDownList();
horas.ID = row["Multiplo"].ToString() + "drop";
horas.SelectedIndexChanged += new EventHandler(horachange);
horas.Attributes.Add("OnSelectedIndexChange", "horachange");
horas.AutoPostBack = true;
for (int i = 0; i < 24; i++)
{
ListItem hor = new ListItem();
if (i < 10)
hor.Text = "0" + i.ToString() + ":00";
else
hor.Text = i.ToString() + ":00";
horas.Items.Add(hor);
}
hora.Controls.Add(horas);
r.Cells.Add(hora);
TableCell canthoras = new TableCell();
canthoras.CssClass = "col";
canthoras.Text = row["Total Hrs"] as string;
r.Cells.Add(canthoras);
TableCell termino = new TableCell();
termino.ID = row["Multiplo"] + "end";
termino.CssClass = "col";
termino.Text = (Int32.Parse(horas.SelectedValue.Remove(2, 3)) + Int32.Parse(canthoras.Text)).ToString() + ":00";
r.Cells.Add(termino);
TableCell adfert = new TableCell();
Button but = new Button();
but.ID = row["Multiplo"] + "_fert";
but.Click += new EventHandler(addfert);
but.Text = "Agregar Fertilización";
adfert.Controls.Add(but);
r.Cells.Add(adfert);
riego.Rows.Add(r);
}
}
}
void addfert(object sender, EventArgs e)
{
Button b = sender as Button;
TableRow r = b.Parent.Parent as TableRow;
if (!fertilizacion.Visible)
fertilizacion.Visible = true;
TableRow row = new TableRow();
row.ID = r.ID + "fert";
row.CssClass = "row";
TableCell horasfert = new TableCell();
horasfert.CssClass = "col";
TableCell horainit = new TableCell();
horainit.CssClass = "col";
TableCell product = new TableCell();
product.CssClass = "col";
TableCell unit = new TableCell();
unit.CssClass = "col";
TableCell hectas = new TableCell();
hectas.CssClass = "col";
TableCell HAS = new TableCell();
HAS.CssClass = "col";
TableCell Mult = new TableCell();
Mult.CssClass = "col";
TextBox horasferti = new TextBox();
horasferti.EnableViewState = true;
horasferti.CssClass = "form-control";
horasferti.ID = r.ID + "_hor_fert";
horasferti.Text = r.Cells[3].Text;
horasfert.Controls.Add(horasferti);
DropDownList horain = new DropDownList();
horain.EnableViewState = true;
for (int i = 1; i <= 24; i++)
horain.Items.Add(i.ToString() + ":00");
horainit.Controls.Add(horain);
TextBox producto = new TextBox();
producto.EnableViewState = true;
producto.CssClass = "form-control";
product.Controls.Add(producto);
unit.Text = "Grs";
TextBox hecta = new TextBox();
hecta.EnableViewState = true;
hecta.CssClass = "form-control";
hectas.Controls.Add(hecta);
TextBox ha = new TextBox();
ha.EnableViewState = true;
ha.CssClass = "form-control";
HAS.Controls.Add(ha);
Mult.Text = r.ID;
row.Cells.Add(horasfert);
row.Cells.Add(horainit);
row.Cells.Add(product);
row.Cells.Add(unit);
row.Cells.Add(hectas);
row.Cells.Add(HAS);
row.Cells.Add(Mult);
row.EnableViewState = true;
fertilizacion.Rows.Add(row);
}
c# html asp.net .net html5
add a comment |
I have been searching the site for a good answer to this type of problem but everyone has a different way of solving this plus my english has been a bit lackluster regarding documentation:
https://msdn.microsoft.com/en-us/library/bb399001.aspx
I tried using Session variable to cast the Table OnPostBack but it does not work anyway:
My HTML Code (reduced) is:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="popup.aspx.cs" Inherits="AgroRiego.popup" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Horario</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<form id="form1" runat="server">
<div class="container mb-5">
<div class="row">
<div class="offset-4 col-4">
<asp:DropDownList ID="select_predo" AutoPostBack="true" runat="server" CssClass="form-control"></asp:DropDownList>
</div>
</div>
</div>
<div class="container">
<asp:Table ID="riego" ViewStateMode="Enabled" runat="server" CssClass="container">
<asp:TableHeaderRow CssClass="row">
<asp:TableHeaderCell CssClass="col" Enabled="false">Múltiplo</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Dia programado</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col" Enabled="false">Horario</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Cantidad de Horas</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Horario término</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Fertilización</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</div>
<div class="container">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Table ID="fertilizacion" EnableViewState="true" Visible="false" runat="server" CssClass="container">
<asp:TableHeaderRow CssClass="row">
<asp:TableHeaderCell CssClass="col">Horas de Fertilización</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Hora de Inicio</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Producto</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Unidad</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Hectareas</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Has</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Mult</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Basically, i add rows dinamically on the first table with a button that OnClick adds a row to the second table, problem is the table only saves the last row added! and i still don't understand why it does not save the previous iteration, if someone gives me an answer with a thorough explanation i'd love him till the ends of my days.
Server side code:
public partial class popup : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable predos = Session["predos"] as DataTable;
if (!IsPostBack)
{
foreach (DataRow row in predos.Rows)
select_predo.Items.Add(row["ID"].ToString());
Deploy(predos.Rows[0]["ID"].ToString());
}
else
{
Deploy(select_predo.SelectedValue);
}
}
public void Deploy(string first_let)
{
DataTable taba = Session[0] as DataTable;
foreach (DataRow row in taba.Rows)
{
if (row["Multiplo"].ToString().Contains(first_let))
{
TableRow r = new TableRow();
r.ID = row["Multiplo"].ToString();
r.CssClass = "row";
TableCell sector = new TableCell();
sector.CssClass = "col";
sector.Text = row["Multiplo"].ToString();
r.Cells.Add(sector);
TableCell dia = new TableCell();
dia.CssClass = "col";
dia.Text = DateTime.Parse(row["Fecha"] as string).ToShortDateString();
r.Cells.Add(dia);
TableCell hora = new TableCell();
hora.CssClass = "col";
DropDownList horas = new DropDownList();
horas.ID = row["Multiplo"].ToString() + "drop";
horas.SelectedIndexChanged += new EventHandler(horachange);
horas.Attributes.Add("OnSelectedIndexChange", "horachange");
horas.AutoPostBack = true;
for (int i = 0; i < 24; i++)
{
ListItem hor = new ListItem();
if (i < 10)
hor.Text = "0" + i.ToString() + ":00";
else
hor.Text = i.ToString() + ":00";
horas.Items.Add(hor);
}
hora.Controls.Add(horas);
r.Cells.Add(hora);
TableCell canthoras = new TableCell();
canthoras.CssClass = "col";
canthoras.Text = row["Total Hrs"] as string;
r.Cells.Add(canthoras);
TableCell termino = new TableCell();
termino.ID = row["Multiplo"] + "end";
termino.CssClass = "col";
termino.Text = (Int32.Parse(horas.SelectedValue.Remove(2, 3)) + Int32.Parse(canthoras.Text)).ToString() + ":00";
r.Cells.Add(termino);
TableCell adfert = new TableCell();
Button but = new Button();
but.ID = row["Multiplo"] + "_fert";
but.Click += new EventHandler(addfert);
but.Text = "Agregar Fertilización";
adfert.Controls.Add(but);
r.Cells.Add(adfert);
riego.Rows.Add(r);
}
}
}
void addfert(object sender, EventArgs e)
{
Button b = sender as Button;
TableRow r = b.Parent.Parent as TableRow;
if (!fertilizacion.Visible)
fertilizacion.Visible = true;
TableRow row = new TableRow();
row.ID = r.ID + "fert";
row.CssClass = "row";
TableCell horasfert = new TableCell();
horasfert.CssClass = "col";
TableCell horainit = new TableCell();
horainit.CssClass = "col";
TableCell product = new TableCell();
product.CssClass = "col";
TableCell unit = new TableCell();
unit.CssClass = "col";
TableCell hectas = new TableCell();
hectas.CssClass = "col";
TableCell HAS = new TableCell();
HAS.CssClass = "col";
TableCell Mult = new TableCell();
Mult.CssClass = "col";
TextBox horasferti = new TextBox();
horasferti.EnableViewState = true;
horasferti.CssClass = "form-control";
horasferti.ID = r.ID + "_hor_fert";
horasferti.Text = r.Cells[3].Text;
horasfert.Controls.Add(horasferti);
DropDownList horain = new DropDownList();
horain.EnableViewState = true;
for (int i = 1; i <= 24; i++)
horain.Items.Add(i.ToString() + ":00");
horainit.Controls.Add(horain);
TextBox producto = new TextBox();
producto.EnableViewState = true;
producto.CssClass = "form-control";
product.Controls.Add(producto);
unit.Text = "Grs";
TextBox hecta = new TextBox();
hecta.EnableViewState = true;
hecta.CssClass = "form-control";
hectas.Controls.Add(hecta);
TextBox ha = new TextBox();
ha.EnableViewState = true;
ha.CssClass = "form-control";
HAS.Controls.Add(ha);
Mult.Text = r.ID;
row.Cells.Add(horasfert);
row.Cells.Add(horainit);
row.Cells.Add(product);
row.Cells.Add(unit);
row.Cells.Add(hectas);
row.Cells.Add(HAS);
row.Cells.Add(Mult);
row.EnableViewState = true;
fertilizacion.Rows.Add(row);
}
c# html asp.net .net html5
add a comment |
I have been searching the site for a good answer to this type of problem but everyone has a different way of solving this plus my english has been a bit lackluster regarding documentation:
https://msdn.microsoft.com/en-us/library/bb399001.aspx
I tried using Session variable to cast the Table OnPostBack but it does not work anyway:
My HTML Code (reduced) is:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="popup.aspx.cs" Inherits="AgroRiego.popup" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Horario</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<form id="form1" runat="server">
<div class="container mb-5">
<div class="row">
<div class="offset-4 col-4">
<asp:DropDownList ID="select_predo" AutoPostBack="true" runat="server" CssClass="form-control"></asp:DropDownList>
</div>
</div>
</div>
<div class="container">
<asp:Table ID="riego" ViewStateMode="Enabled" runat="server" CssClass="container">
<asp:TableHeaderRow CssClass="row">
<asp:TableHeaderCell CssClass="col" Enabled="false">Múltiplo</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Dia programado</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col" Enabled="false">Horario</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Cantidad de Horas</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Horario término</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Fertilización</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</div>
<div class="container">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Table ID="fertilizacion" EnableViewState="true" Visible="false" runat="server" CssClass="container">
<asp:TableHeaderRow CssClass="row">
<asp:TableHeaderCell CssClass="col">Horas de Fertilización</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Hora de Inicio</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Producto</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Unidad</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Hectareas</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Has</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Mult</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Basically, i add rows dinamically on the first table with a button that OnClick adds a row to the second table, problem is the table only saves the last row added! and i still don't understand why it does not save the previous iteration, if someone gives me an answer with a thorough explanation i'd love him till the ends of my days.
Server side code:
public partial class popup : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable predos = Session["predos"] as DataTable;
if (!IsPostBack)
{
foreach (DataRow row in predos.Rows)
select_predo.Items.Add(row["ID"].ToString());
Deploy(predos.Rows[0]["ID"].ToString());
}
else
{
Deploy(select_predo.SelectedValue);
}
}
public void Deploy(string first_let)
{
DataTable taba = Session[0] as DataTable;
foreach (DataRow row in taba.Rows)
{
if (row["Multiplo"].ToString().Contains(first_let))
{
TableRow r = new TableRow();
r.ID = row["Multiplo"].ToString();
r.CssClass = "row";
TableCell sector = new TableCell();
sector.CssClass = "col";
sector.Text = row["Multiplo"].ToString();
r.Cells.Add(sector);
TableCell dia = new TableCell();
dia.CssClass = "col";
dia.Text = DateTime.Parse(row["Fecha"] as string).ToShortDateString();
r.Cells.Add(dia);
TableCell hora = new TableCell();
hora.CssClass = "col";
DropDownList horas = new DropDownList();
horas.ID = row["Multiplo"].ToString() + "drop";
horas.SelectedIndexChanged += new EventHandler(horachange);
horas.Attributes.Add("OnSelectedIndexChange", "horachange");
horas.AutoPostBack = true;
for (int i = 0; i < 24; i++)
{
ListItem hor = new ListItem();
if (i < 10)
hor.Text = "0" + i.ToString() + ":00";
else
hor.Text = i.ToString() + ":00";
horas.Items.Add(hor);
}
hora.Controls.Add(horas);
r.Cells.Add(hora);
TableCell canthoras = new TableCell();
canthoras.CssClass = "col";
canthoras.Text = row["Total Hrs"] as string;
r.Cells.Add(canthoras);
TableCell termino = new TableCell();
termino.ID = row["Multiplo"] + "end";
termino.CssClass = "col";
termino.Text = (Int32.Parse(horas.SelectedValue.Remove(2, 3)) + Int32.Parse(canthoras.Text)).ToString() + ":00";
r.Cells.Add(termino);
TableCell adfert = new TableCell();
Button but = new Button();
but.ID = row["Multiplo"] + "_fert";
but.Click += new EventHandler(addfert);
but.Text = "Agregar Fertilización";
adfert.Controls.Add(but);
r.Cells.Add(adfert);
riego.Rows.Add(r);
}
}
}
void addfert(object sender, EventArgs e)
{
Button b = sender as Button;
TableRow r = b.Parent.Parent as TableRow;
if (!fertilizacion.Visible)
fertilizacion.Visible = true;
TableRow row = new TableRow();
row.ID = r.ID + "fert";
row.CssClass = "row";
TableCell horasfert = new TableCell();
horasfert.CssClass = "col";
TableCell horainit = new TableCell();
horainit.CssClass = "col";
TableCell product = new TableCell();
product.CssClass = "col";
TableCell unit = new TableCell();
unit.CssClass = "col";
TableCell hectas = new TableCell();
hectas.CssClass = "col";
TableCell HAS = new TableCell();
HAS.CssClass = "col";
TableCell Mult = new TableCell();
Mult.CssClass = "col";
TextBox horasferti = new TextBox();
horasferti.EnableViewState = true;
horasferti.CssClass = "form-control";
horasferti.ID = r.ID + "_hor_fert";
horasferti.Text = r.Cells[3].Text;
horasfert.Controls.Add(horasferti);
DropDownList horain = new DropDownList();
horain.EnableViewState = true;
for (int i = 1; i <= 24; i++)
horain.Items.Add(i.ToString() + ":00");
horainit.Controls.Add(horain);
TextBox producto = new TextBox();
producto.EnableViewState = true;
producto.CssClass = "form-control";
product.Controls.Add(producto);
unit.Text = "Grs";
TextBox hecta = new TextBox();
hecta.EnableViewState = true;
hecta.CssClass = "form-control";
hectas.Controls.Add(hecta);
TextBox ha = new TextBox();
ha.EnableViewState = true;
ha.CssClass = "form-control";
HAS.Controls.Add(ha);
Mult.Text = r.ID;
row.Cells.Add(horasfert);
row.Cells.Add(horainit);
row.Cells.Add(product);
row.Cells.Add(unit);
row.Cells.Add(hectas);
row.Cells.Add(HAS);
row.Cells.Add(Mult);
row.EnableViewState = true;
fertilizacion.Rows.Add(row);
}
c# html asp.net .net html5
I have been searching the site for a good answer to this type of problem but everyone has a different way of solving this plus my english has been a bit lackluster regarding documentation:
https://msdn.microsoft.com/en-us/library/bb399001.aspx
I tried using Session variable to cast the Table OnPostBack but it does not work anyway:
My HTML Code (reduced) is:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="popup.aspx.cs" Inherits="AgroRiego.popup" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Horario</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<form id="form1" runat="server">
<div class="container mb-5">
<div class="row">
<div class="offset-4 col-4">
<asp:DropDownList ID="select_predo" AutoPostBack="true" runat="server" CssClass="form-control"></asp:DropDownList>
</div>
</div>
</div>
<div class="container">
<asp:Table ID="riego" ViewStateMode="Enabled" runat="server" CssClass="container">
<asp:TableHeaderRow CssClass="row">
<asp:TableHeaderCell CssClass="col" Enabled="false">Múltiplo</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Dia programado</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col" Enabled="false">Horario</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Cantidad de Horas</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Horario término</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Fertilización</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</div>
<div class="container">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Table ID="fertilizacion" EnableViewState="true" Visible="false" runat="server" CssClass="container">
<asp:TableHeaderRow CssClass="row">
<asp:TableHeaderCell CssClass="col">Horas de Fertilización</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Hora de Inicio</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Producto</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Unidad</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Hectareas</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Has</asp:TableHeaderCell>
<asp:TableHeaderCell CssClass="col">Mult</asp:TableHeaderCell>
</asp:TableHeaderRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
Basically, i add rows dinamically on the first table with a button that OnClick adds a row to the second table, problem is the table only saves the last row added! and i still don't understand why it does not save the previous iteration, if someone gives me an answer with a thorough explanation i'd love him till the ends of my days.
Server side code:
public partial class popup : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable predos = Session["predos"] as DataTable;
if (!IsPostBack)
{
foreach (DataRow row in predos.Rows)
select_predo.Items.Add(row["ID"].ToString());
Deploy(predos.Rows[0]["ID"].ToString());
}
else
{
Deploy(select_predo.SelectedValue);
}
}
public void Deploy(string first_let)
{
DataTable taba = Session[0] as DataTable;
foreach (DataRow row in taba.Rows)
{
if (row["Multiplo"].ToString().Contains(first_let))
{
TableRow r = new TableRow();
r.ID = row["Multiplo"].ToString();
r.CssClass = "row";
TableCell sector = new TableCell();
sector.CssClass = "col";
sector.Text = row["Multiplo"].ToString();
r.Cells.Add(sector);
TableCell dia = new TableCell();
dia.CssClass = "col";
dia.Text = DateTime.Parse(row["Fecha"] as string).ToShortDateString();
r.Cells.Add(dia);
TableCell hora = new TableCell();
hora.CssClass = "col";
DropDownList horas = new DropDownList();
horas.ID = row["Multiplo"].ToString() + "drop";
horas.SelectedIndexChanged += new EventHandler(horachange);
horas.Attributes.Add("OnSelectedIndexChange", "horachange");
horas.AutoPostBack = true;
for (int i = 0; i < 24; i++)
{
ListItem hor = new ListItem();
if (i < 10)
hor.Text = "0" + i.ToString() + ":00";
else
hor.Text = i.ToString() + ":00";
horas.Items.Add(hor);
}
hora.Controls.Add(horas);
r.Cells.Add(hora);
TableCell canthoras = new TableCell();
canthoras.CssClass = "col";
canthoras.Text = row["Total Hrs"] as string;
r.Cells.Add(canthoras);
TableCell termino = new TableCell();
termino.ID = row["Multiplo"] + "end";
termino.CssClass = "col";
termino.Text = (Int32.Parse(horas.SelectedValue.Remove(2, 3)) + Int32.Parse(canthoras.Text)).ToString() + ":00";
r.Cells.Add(termino);
TableCell adfert = new TableCell();
Button but = new Button();
but.ID = row["Multiplo"] + "_fert";
but.Click += new EventHandler(addfert);
but.Text = "Agregar Fertilización";
adfert.Controls.Add(but);
r.Cells.Add(adfert);
riego.Rows.Add(r);
}
}
}
void addfert(object sender, EventArgs e)
{
Button b = sender as Button;
TableRow r = b.Parent.Parent as TableRow;
if (!fertilizacion.Visible)
fertilizacion.Visible = true;
TableRow row = new TableRow();
row.ID = r.ID + "fert";
row.CssClass = "row";
TableCell horasfert = new TableCell();
horasfert.CssClass = "col";
TableCell horainit = new TableCell();
horainit.CssClass = "col";
TableCell product = new TableCell();
product.CssClass = "col";
TableCell unit = new TableCell();
unit.CssClass = "col";
TableCell hectas = new TableCell();
hectas.CssClass = "col";
TableCell HAS = new TableCell();
HAS.CssClass = "col";
TableCell Mult = new TableCell();
Mult.CssClass = "col";
TextBox horasferti = new TextBox();
horasferti.EnableViewState = true;
horasferti.CssClass = "form-control";
horasferti.ID = r.ID + "_hor_fert";
horasferti.Text = r.Cells[3].Text;
horasfert.Controls.Add(horasferti);
DropDownList horain = new DropDownList();
horain.EnableViewState = true;
for (int i = 1; i <= 24; i++)
horain.Items.Add(i.ToString() + ":00");
horainit.Controls.Add(horain);
TextBox producto = new TextBox();
producto.EnableViewState = true;
producto.CssClass = "form-control";
product.Controls.Add(producto);
unit.Text = "Grs";
TextBox hecta = new TextBox();
hecta.EnableViewState = true;
hecta.CssClass = "form-control";
hectas.Controls.Add(hecta);
TextBox ha = new TextBox();
ha.EnableViewState = true;
ha.CssClass = "form-control";
HAS.Controls.Add(ha);
Mult.Text = r.ID;
row.Cells.Add(horasfert);
row.Cells.Add(horainit);
row.Cells.Add(product);
row.Cells.Add(unit);
row.Cells.Add(hectas);
row.Cells.Add(HAS);
row.Cells.Add(Mult);
row.EnableViewState = true;
fertilizacion.Rows.Add(row);
}
c# html asp.net .net html5
c# html asp.net .net html5
edited Nov 19 '18 at 14:27
Logan
2,09932856
2,09932856
asked Nov 19 '18 at 14:16
Gonzalo
5510
5510
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376534%2fusing-updatepanel-or-any-other-method-to-save-dynamic-rows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376534%2fusing-updatepanel-or-any-other-method-to-save-dynamic-rows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown