473,734 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 dropdownselecte d_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%"
AutoGenerateCol umns="False">
<ItemStyle CssClass="regis tros"></ItemStyle>
<HeaderStyle CssClass="titul ostablas"></HeaderStyle>
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:LinkButt on runat="server" Text="Eliminar"
CommandName="De lete" CausesValidatio n="false"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Pro ducto">
<ItemTemplate >
<asp:DropDownLi st id="ddlproducto s" runat="server"
AutoPostBack="T rue"
OnSelectedIndex Changed="DropDo wn_SelectedInde xChanged"></asp:DropDownLis t>
</ItemTemplate>
<FooterTemplate >
<asp:LinkButt on id="LinkButton1 " runat="server"
CommandName="ag regarproducto"> Agregar Producto</asp:LinkButton>
</FooterTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Can tidad">
<ItemTemplate >
<asp:TextBox id="txtcantidad " runat="server" Width="44px"
CssClass="texto s" AutoPostBack="T rue"
OnTextChanged=" calcularsubtota l"></asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Pre cio">
<ItemTemplate >
<asp:TextBox id=txtprecio runat="server" Width="60px"
CssClass="texto s" Text='<%# DataBinder.Eval (Container,
"DataItem.preci oespecifico") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Iva ">
<ItemTemplate >
<asp:TextBox id=txtivaporpro ducto runat="server" Width="36px"
CssClass="texto s" Text='<%# DataBinder.Eval (Container, "DataItem.i va") %>'>
</asp:TextBox><FO NT size="2">%</FONT>
</ItemTemplate>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Sub total">
<ItemTemplate >
<asp:TextBox id="txtsubtotal porproducto" runat="server"
Width="68px" CssClass="texto s"></asp:TextBox>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:datagrid>

the function that adds a new row is this.

Private Sub LinkButton2_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles LinkButton2.Cli ck
Dim tcells As TableCellCollec tion

'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.Au toPostBack = True
'ddlproductos = e.Item.Cells(1) .FindControl("d dlproductos")
ddlproductos.At tributes.Add("O nSelectedIndexC hanged",
"DropDown_Selec tedIndexChanged ")

ddlproductos.Da taSource = CType(Session(" productos"), DataSet)
ddlproductos.Da taTextField = "descripcio n"
ddlproductos.Da taValueField = "idproducto "
ddlproductos.Da taBind()

productcell.Con trols.Add(ddlpr oductos)
Dim lnkbutton As New LinkButton
lnkbutton.Text = "Eliminar"
lnkbutton.Comma ndName = "Delete"

lnkeliminarcel. Controls.Add(ln kbutton)
Dim txtcantidad As New TextBox
txtcantidad.Tex t = 1
txtcantidad.Css Class = "textos"
txtcantidad.Wid th = Unit.Pixel(44)

cantidadcell.Co ntrols.Add(txtc antidad)

Dim txtprecio As New TextBox
txtprecio.CssCl ass = "textos"
txtprecio.Width = Unit.Pixel(60)
txtprecio.Text =
objconsultas.pr ecioxproducto(d dlproductos.Sel ectedValue)
preciocell.Cont rols.Add(txtpre cio)

Dim txtivaporproduc to As New TextBox
txtivaporproduc to.CssClass = "textos"
txtivaporproduc to.Width = Unit.Pixel(36)
txtivaporproduc to.Text =
objconsultas.iv aporproducto(dd lproductos.Sele ctedValue)
taxescell.Contr ols.Add(txtivap orproducto)

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

Dim txtsubtotalporp roducto As New TextBox

txtsubtotalporp roducto.CssClas s = "textos"
txtsubtotalporp roducto.Width = Unit.Pixel(68)

txtsubtotalporp roducto.Text = subtotal.ToStri ng
subtotalcell.Co ntrols.Add(txts ubtotalporprodu cto)
Dim di As New DataGridItem(0, 0, ListItemType.It em)
di.Cells.Add(ln keliminarcel)
di.Cells.Add(pr oductcell)
di.Cells.Add(ca ntidadcell)
di.Cells.Add(pr eciocell)
di.Cells.Add(ta xescell)
di.Cells.Add(su btotalcell)

dgpedidos.Contr ols(0).Controls .Add(di)

End Sub

I also put something on the itemdatabound ç

Private Sub dgpedidos_ItemD ataBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
dgpedidos.ItemD ataBound
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
Dim ddlproductos As New DropDownList
ddlproductos.Au toPostBack = True
ddlproductos = e.Item.Cells(1) .FindControl("d dlproductos")
ddlproductos.At tributes.Add("O nSelectedIndexC hanged",
"DropDown_Selec tedIndexChanged ")

ddlproductos.Da taSource = CType(Session(" productos"), DataSet)
ddlproductos.Da taTextField = "descripcio n"
ddlproductos.Da taValueField = "idproducto "
ddlproductos.Da taBind()
Dim txtquantity As TextBox
txtquantity = e.Item.Cells(2) .Controls(1)
txtquantity.Tex t = 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.Tex t = (Convert.ToInt3 2(txtquantity.T ext) *
Convert.ToInt32 (txtprice.Text) ) - (Convert.ToInt3 2(txtquantity.T ext) *
Convert.ToInt32 (txtprice.Text) * (txtiva.Text / 100))
recorrerdatagri dycalcular()
End If
End Sub

Nov 19 '05 #1
0 1534

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

Similar topics

2
17031
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 the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
1
4334
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 (watch the layout, some have child controls):
1
1372
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 datagrid_Update function I get an Object reference not set to an instance of an object. I am reakky stuck here and I would appreciate any help from you guys.
15
3126
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 OnSelectedIndex event is not fired if you select the first item. Does anyone know of an easy way to do this?
0
2909
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 strDataValueField; string strDataTextField; public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
1
3226
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 both selectedIndex has the same reference and modifying the first one also automatically modify the second one. For example:
2
2018
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 compile time errors stating the control doesn't exist in the current content: <asp:DataGrid ID="tmp" runat="server"> <Columns>
1
1794
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 inside dropdownlist are personnel_number, firstname,lastname,email.position_title I have a datagrid that view out all my data when: ---1st time page load, user will key in firstname or lastname then result will be display in the datagrid ---2nd...
0
1774
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 a user control (long story). Anyway, the user clicks a save button on the parent control to initiate the postback. The parent then calls a Save method (in the child control) from the button event handler. When I iterate through the datagrid...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.