Using UpdatePanel or any other method to save dynamic rows
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
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 |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 at 14:27
Logan
2,08932856
2,08932856
asked Nov 19 at 14:16
Gonzalo
559
559
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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