473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Losing one row of datagrid when changing dropdownlist inside it.

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

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

Nov 19 '05 #1
0 1502

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
1
by: Michael Kolias | last post by:
Hi everybody, I am having a problem getting the selected value of a drop down list that is populated dynamically inside a datagrid control. When I try to access the selected item on the...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
1
by: marcbb | last post by:
Hi all, I have a really strange problem working with Dropdownlists in a DataGrid. I'm trying to preselect some values from the DropDownlist for each row in the DataGrid, but it seems that...
2
by: steven | last post by:
i've got a dropDownList that I'm trying to populate from my code behind as follows: uxVehicleColourEdit.DataSource = oDsLookups.Tables; if the dropDown is placed inside a datagrid, i get...
1
by: simonyong | last post by:
hello, everyone im a newbie to asp.net, getting nut with just a simple stuff please give me some direction How to use dropdownlist when user select one of the method in dropdownlist The fields...
0
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.