L
Luis Esteban Valencia
Please help me if possible
Its only adding a row. When I click again it steps into the function but
doesnt add it to the page.
Private Sub LinkButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles LinkButton2.Click
Dim tcells As TableCellCollection
'tcells = e.Item.Cells
Dim lnkeliminarcel As New TableCell
Dim productcell As New TableCell
Dim cantidadcell As New TableCell
Dim preciocell As New TableCell
Dim taxescell As New TableCell
Dim subtotalcell As New TableCell
Dim ddlproductos As New DropDownList
ddlproductos.AutoPostBack = True
'ddlproductos = e.Item.Cells(1).FindControl("ddlproductos")
ddlproductos.DataSource = CType(Session("productos"), DataSet)
ddlproductos.DataTextField = "descripcion"
ddlproductos.DataValueField = "idproducto"
ddlproductos.DataBind()
productcell.Controls.Add(ddlproductos)
Dim lnkbutton As New LinkButton
lnkbutton.Text = "Eliminar"
lnkbutton.CommandName = "Delete"
lnkeliminarcel.Controls.Add(lnkbutton)
Dim txtcantidad As New TextBox
txtcantidad.Text = 1
txtcantidad.CssClass = "textos"
txtcantidad.Width = Unit.Pixel(44)
cantidadcell.Controls.Add(txtcantidad)
Dim txtprecio As New TextBox
txtprecio.CssClass = "textos"
txtprecio.Width = Unit.Pixel(60)
txtprecio.Text = objconsultas.precioxproducto(ddlproductos.SelectedValue)
preciocell.Controls.Add(txtprecio)
Dim txtivaporproducto As New TextBox
txtivaporproducto.CssClass = "textos"
txtivaporproducto.Width = Unit.Pixel(36)
txtivaporproducto.Text =
objconsultas.ivaporproducto(ddlproductos.SelectedValue)
taxescell.Controls.Add(txtivaporproducto)
Dim cantidad As Int32 = Convert.ToInt32(txtcantidad.Text)
Dim price As Int32 = Convert.ToInt32(txtprecio.Text)
Dim subtotal As Int32 = cantidad * price
Dim txtsubtotalporproducto As New TextBox
txtsubtotalporproducto.CssClass = "textos"
txtsubtotalporproducto.Width = Unit.Pixel(68)
txtsubtotalporproducto.Text = subtotal.ToString
subtotalcell.Controls.Add(txtsubtotalporproducto)
Dim di As New DataGridItem(0, 0, ListItemType.Item)
di.Cells.Add(lnkeliminarcel)
di.Cells.Add(productcell)
di.Cells.Add(cantidadcell)
di.Cells.Add(preciocell)
di.Cells.Add(taxescell)
di.Cells.Add(subtotalcell)
dgpedidos.Controls(0).Controls.Add(di)
End Sub
<asp:datagrid id="dgpedidos" runat="server" Width="100%"
AutoGenerateColumns="False">
<ItemStyle CssClass="registros"></ItemStyle>
<HeaderStyle CssClass="titulostablas"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Eliminar"
CommandName="Delete" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Producto">
<ItemTemplate>
<asp
ropDownList id="ddlproductos" runat="server"
AutoPostBack="True"></asp
ropDownList>
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton id="LinkButton1" runat="server"
CommandName="agregarproducto">Agregar Producto</asp:LinkButton>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Cantidad">
<ItemTemplate>
<asp:TextBox id="txtcantidad" runat="server" Width="44px"
CssClass="textos" AutoPostBack="True"
OnTextChanged="calcularsubtotal"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Precio">
<ItemTemplate>
<asp:TextBox id=txtprecio runat="server" Width="60px"
CssClass="textos" Text='<%# DataBinder.Eval(Container,
"DataItem.precioespecifico") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Iva">
<ItemTemplate>
<asp:TextBox id=txtivaporproducto runat="server" Width="36px"
CssClass="textos" Text='<%# DataBinder.Eval(Container, "DataItem.iva") %>'>
</asp:TextBox><FONT size="2">%</FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Subtotal">
<ItemTemplate>
<asp:TextBox id="txtsubtotalporproducto" runat="server"
Width="68px" CssClass="textos"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></P>
</TD>
</TR>
<TR>
<TD width="50%"></TD>
<TD width="68" style="WIDTH: 68px"></TD>
<TD width="15%"></TD>
<TD width="15%"><STRONG><FONT
size="3">Subtotal</FONT></STRONG></TD>
<TD width="15%"><STRONG><FONT size="3"><asp:textbox
id="txtsubtotalpedido" runat="server" Width="80px"
CssClass="textos"></asp:textbox></FONT></STRONG></TD>
</TR>
<TR>
<TD width="50%"><STRONG><FONT size="3">
<asp:LinkButton id="LinkButton2" runat="server"
CommandName="agregarproducto">Agregar Producto</asp:LinkButton>
Its only adding a row. When I click again it steps into the function but
doesnt add it to the page.
Private Sub LinkButton2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles LinkButton2.Click
Dim tcells As TableCellCollection
'tcells = e.Item.Cells
Dim lnkeliminarcel As New TableCell
Dim productcell As New TableCell
Dim cantidadcell As New TableCell
Dim preciocell As New TableCell
Dim taxescell As New TableCell
Dim subtotalcell As New TableCell
Dim ddlproductos As New DropDownList
ddlproductos.AutoPostBack = True
'ddlproductos = e.Item.Cells(1).FindControl("ddlproductos")
ddlproductos.DataSource = CType(Session("productos"), DataSet)
ddlproductos.DataTextField = "descripcion"
ddlproductos.DataValueField = "idproducto"
ddlproductos.DataBind()
productcell.Controls.Add(ddlproductos)
Dim lnkbutton As New LinkButton
lnkbutton.Text = "Eliminar"
lnkbutton.CommandName = "Delete"
lnkeliminarcel.Controls.Add(lnkbutton)
Dim txtcantidad As New TextBox
txtcantidad.Text = 1
txtcantidad.CssClass = "textos"
txtcantidad.Width = Unit.Pixel(44)
cantidadcell.Controls.Add(txtcantidad)
Dim txtprecio As New TextBox
txtprecio.CssClass = "textos"
txtprecio.Width = Unit.Pixel(60)
txtprecio.Text = objconsultas.precioxproducto(ddlproductos.SelectedValue)
preciocell.Controls.Add(txtprecio)
Dim txtivaporproducto As New TextBox
txtivaporproducto.CssClass = "textos"
txtivaporproducto.Width = Unit.Pixel(36)
txtivaporproducto.Text =
objconsultas.ivaporproducto(ddlproductos.SelectedValue)
taxescell.Controls.Add(txtivaporproducto)
Dim cantidad As Int32 = Convert.ToInt32(txtcantidad.Text)
Dim price As Int32 = Convert.ToInt32(txtprecio.Text)
Dim subtotal As Int32 = cantidad * price
Dim txtsubtotalporproducto As New TextBox
txtsubtotalporproducto.CssClass = "textos"
txtsubtotalporproducto.Width = Unit.Pixel(68)
txtsubtotalporproducto.Text = subtotal.ToString
subtotalcell.Controls.Add(txtsubtotalporproducto)
Dim di As New DataGridItem(0, 0, ListItemType.Item)
di.Cells.Add(lnkeliminarcel)
di.Cells.Add(productcell)
di.Cells.Add(cantidadcell)
di.Cells.Add(preciocell)
di.Cells.Add(taxescell)
di.Cells.Add(subtotalcell)
dgpedidos.Controls(0).Controls.Add(di)
End Sub
<asp:datagrid id="dgpedidos" runat="server" Width="100%"
AutoGenerateColumns="False">
<ItemStyle CssClass="registros"></ItemStyle>
<HeaderStyle CssClass="titulostablas"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton runat="server" Text="Eliminar"
CommandName="Delete" CausesValidation="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Producto">
<ItemTemplate>
<asp
AutoPostBack="True"></asp
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton id="LinkButton1" runat="server"
CommandName="agregarproducto">Agregar Producto</asp:LinkButton>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Cantidad">
<ItemTemplate>
<asp:TextBox id="txtcantidad" runat="server" Width="44px"
CssClass="textos" AutoPostBack="True"
OnTextChanged="calcularsubtotal"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Precio">
<ItemTemplate>
<asp:TextBox id=txtprecio runat="server" Width="60px"
CssClass="textos" Text='<%# DataBinder.Eval(Container,
"DataItem.precioespecifico") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Iva">
<ItemTemplate>
<asp:TextBox id=txtivaporproducto runat="server" Width="36px"
CssClass="textos" Text='<%# DataBinder.Eval(Container, "DataItem.iva") %>'>
</asp:TextBox><FONT size="2">%</FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Subtotal">
<ItemTemplate>
<asp:TextBox id="txtsubtotalporproducto" runat="server"
Width="68px" CssClass="textos"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></P>
</TD>
</TR>
<TR>
<TD width="50%"></TD>
<TD width="68" style="WIDTH: 68px"></TD>
<TD width="15%"></TD>
<TD width="15%"><STRONG><FONT
size="3">Subtotal</FONT></STRONG></TD>
<TD width="15%"><STRONG><FONT size="3"><asp:textbox
id="txtsubtotalpedido" runat="server" Width="80px"
CssClass="textos"></asp:textbox></FONT></STRONG></TD>
</TR>
<TR>
<TD width="50%"><STRONG><FONT size="3">
<asp:LinkButton id="LinkButton2" runat="server"
CommandName="agregarproducto">Agregar Producto</asp:LinkButton>