Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Losing one row of datagrid when changing dropdownlist inside it.

Reply
Thread Tools

Losing one row of datagrid when changing dropdownlist inside it.

 
 
Luis Esteban Valencia
Guest
Posts: n/a
 
      03-23-2005
Thanks in advance for your time-


Hello. I have a datagrid with one row. I have a button that adds a new row.
I am trying to implement that when the user selects one product it must
change the price on the quantity column. Anyway when the user selects the
first dropdownlist the dropdownselected_indexchanged is firring but when the
user chagnes the second dropdownlist its not firing.

aahh! if the user selects any of both dropdownlist the datagrid stays with
only one row?

Whjy??

<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>
<aspropDownList
id="ddlproductos" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="DropDown_SelectedIndexChan ged"></aspropDownList>
</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>

the function that adds a new row is this.

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.Attributes.Add("OnSelectedIndexChange d",
"DropDown_SelectedIndexChanged")

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.Selected Value)
preciocell.Controls.Add(txtprecio)

Dim txtivaporproducto As New TextBox
txtivaporproducto.CssClass = "textos"
txtivaporproducto.Width = Unit.Pixel(36)
txtivaporproducto.Text =
objconsultas.ivaporproducto(ddlproductos.SelectedV alue)
taxescell.Controls.Add(txtivaporproducto)

Dim cantidad As Int32 = Convert.ToInt32(txtcantidad.Text)
Dim price As Int32 = Convert.ToInt32(txtprecio.Text)
Dim subtotal As Decimal = cantidad * price - ((cantidad * price) *
(txtivaporproducto.Text / 100))

Dim txtsubtotalporproducto As New TextBox

txtsubtotalporproducto.CssClass = "textos"
txtsubtotalporproducto.Width = Unit.Pixel(6

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

I also put something on the itemdatabound

Private Sub dgpedidos_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgpedidos.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim ddlproductos As New DropDownList
ddlproductos.AutoPostBack = True
ddlproductos = e.Item.Cells(1).FindControl("ddlproductos")
ddlproductos.Attributes.Add("OnSelectedIndexChange d",
"DropDown_SelectedIndexChanged")

ddlproductos.DataSource = CType(Session("productos"), DataSet)
ddlproductos.DataTextField = "descripcion"
ddlproductos.DataValueField = "idproducto"
ddlproductos.DataBind()


Dim txtquantity As TextBox
txtquantity = e.Item.Cells(2).Controls(1)
txtquantity.Text = 1
Dim txtprice As TextBox
txtprice = e.Item.Cells(3).Controls(1)
Dim txtsubtotal As TextBox

Dim txtiva As TextBox
txtiva = e.Item.Cells(4).Controls(1)
txtsubtotal = e.Item.Cells(5).Controls(1)
txtsubtotal.Text = (Convert.ToInt32(txtquantity.Text) *
Convert.ToInt32(txtprice.Text)) - (Convert.ToInt32(txtquantity.Text) *
Convert.ToInt32(txtprice.Text) * (txtiva.Text / 100))
recorrerdatagridycalcular()
End If
End Sub



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex losing <br> (different from the earlier topic about losing $1) Jason C Perl Misc 4 06-26-2012 10:29 PM
Losing Drives - Finding Drives - Losing Drives mel@no.spam.com Computer Support 2 09-21-2007 10:16 PM
Checkbox and dropdownlist row in repeater row =?Utf-8?B?UmljaGFyZEg=?= ASP .Net 2 03-24-2006 10:48 AM
ok I can do a totals row but how about a percentage row after each data row D ASP .Net Datagrid Control 0 05-23-2005 04:10 PM
Losing one row of datagrid when changing dropdownlist inside it. Luis Esteban Valencia ASP .Net 0 03-23-2005 05:04 PM



Advertisments