473,804 Members | 3,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change row data when dropdownlist changes?

Hello I have a datagrid with a dropdownlist that has the products,
another column has the price of the product and when the user changes
the product it also must change the price how can I achieve that.

Thanks

Datagrid html

<asp:datagrid id="dgpedidos" runat="server" Width="100%"
ShowFooter="Tru e" AutoGenerateCol umns="False">
<ItemStyle CssClass="regis tros"></ItemStyle>
<HeaderStyle CssClass="titul ostablas"></HeaderStyle>
<Columns>
<asp:ButtonColu mn Text="Eliminar"
CommandName="De lete"></asp:ButtonColum n>
<asp:TemplateCo lumn HeaderText="Pro ducto">
<ItemTemplate >
<asp:DropDownLi st id="ddlproducto s" runat="server"> </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"></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",
"{0:N0}%") %>'>
</asp:TextBox>
</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>

And my codebehind

Dim objconsultas As New LBDatos.consult as

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

If Not Page.IsPostBack Then

cargarproductos ()

cargardatagrid( )

End If

End Sub

Public Sub cargarproductos ()

Session("produc tos") =
objconsultas.to dosproductoxCia (Session("idcom pania"))

End Sub

Private Sub cargardatagrid( )

Dim ds As DataSet

Dim dc1 As New DataColumn("Sub Total",
System.Type.Get Type("System.De cimal")) 'i am assuming your stored proc
does not contain a column SubTotal

Dim dc2 As New DataColumn("Can tidad",
System.Type.Get Type("System.In t32"))

ds = objconsultas.pr oductoxCia(Sess ion("idcompania "))

ds.Tables(0).Co lumns.Add(dc2)

dc1.Expression = "Cantidad * Precioespecific o"

ds.Tables(0).Co lumns.Add(dc1)

dgpedidos.DataS ource = ds

dgpedidos.DataB ind()

End Sub



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.Da taSource = CType(Session(" productos"),
DataSet)

ddlproductos.Da taTextField = "descripcio n"

ddlproductos.Da taValueField = "idproducto "

ddlproductos.Da taBind()

End If

End Sub



Private Sub dgpedidos_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
dgpedidos.ItemC ommand

If e.CommandName = "agregarproduct os" Then

Dim di As DataGridItem

di.

End If

End Sub


Nov 19 '05 #1
2 2350
Hi Luis,

You are on the correct path... make Autopostback property of dropdown to true, when selecttion changes in dropdown it will trigger
ItemCommand event.
in item commend event based on selection retreive more infomation about the product like price and u can assign it to textbox

HTH
Regards,
Jignesh Desai.
www.dotnetjini.com
"Luis Esteban Valencia" <lu***@epm.net. co> wrote in message news:uE******** ******@TK2MSFTN GP14.phx.gbl...
Hello I have a datagrid with a dropdownlist that has the products, another column has the price of the product and when the user changes the product it also must change the price how can I achieve that.



Thanks

Datagrid html



<asp:datagrid id="dgpedidos" runat="server" Width="100%" ShowFooter="Tru e" AutoGenerateCol umns="False">

<ItemStyle CssClass="regis tros"></ItemStyle>

<HeaderStyle CssClass="titul ostablas"></HeaderStyle>

<Columns>

<asp:ButtonColu mn Text="Eliminar" CommandName="De lete"></asp:ButtonColum n>

<asp:TemplateCo lumn HeaderText="Pro ducto">

<ItemTemplate >

<asp:DropDownLi st id="ddlproducto s" runat="server"> </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"></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", "{0:N0}%") %>'>

</asp:TextBox>

</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>



And my codebehind



Dim objconsultas As New LBDatos.consult as



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

If Not Page.IsPostBack Then

cargarproductos ()

cargardatagrid( )

End If

End Sub



Public Sub cargarproductos ()

Session("produc tos") = objconsultas.to dosproductoxCia (Session("idcom pania"))

End Sub



Private Sub cargardatagrid( )

Dim ds As DataSet

Dim dc1 As New DataColumn("Sub Total", System.Type.Get Type("System.De cimal")) 'i am assuming your stored proc does not contain a column SubTotal

Dim dc2 As New DataColumn("Can tidad", System.Type.Get Type("System.In t32"))

ds = objconsultas.pr oductoxCia(Sess ion("idcompania "))

ds.Tables(0).Co lumns.Add(dc2)

dc1.Expression = "Cantidad * Precioespecific o"

ds.Tables(0).Co lumns.Add(dc1)

dgpedidos.DataS ource = ds

dgpedidos.DataB ind()



End Sub









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.Da taSource = CType(Session(" productos"), DataSet)

ddlproductos.Da taTextField = "descripcio n"

ddlproductos.Da taValueField = "idproducto "

ddlproductos.Da taBind()

End If

End Sub







Private Sub dgpedidos_ItemC ommand(ByVal source As Object, ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles dgpedidos.ItemC ommand

If e.CommandName = "agregarproduct os" Then

Dim di As DataGridItem

di.





End If

End Sub



Nov 19 '05 #2
How would it be in code?
"Jignesh Desai" <ji***********@ hotmail.com> escribió en el mensaje news:Oo******** ******@TK2MSFTN GP09.phx.gbl...
Hi Luis,

You are on the correct path... make Autopostback property of dropdown to true, when selecttion changes in dropdown it will trigger
ItemCommand event.
in item commend event based on selection retreive more infomation about the product like price and u can assign it to textbox

HTH
Regards,
Jignesh Desai.
www.dotnetjini.com
"Luis Esteban Valencia" <lu***@epm.net. co> wrote in message news:uE******** ******@TK2MSFTN GP14.phx.gbl...
Hello I have a datagrid with a dropdownlist that has the products, another column has the price of the product and when the user changes the product it also must change the price how can I achieve that.



Thanks

Datagrid html



<asp:datagrid id="dgpedidos" runat="server" Width="100%" ShowFooter="Tru e" AutoGenerateCol umns="False">

<ItemStyle CssClass="regis tros"></ItemStyle>

<HeaderStyle CssClass="titul ostablas"></HeaderStyle>

<Columns>

<asp:ButtonColu mn Text="Eliminar" CommandName="De lete"></asp:ButtonColum n>

<asp:TemplateCo lumn HeaderText="Pro ducto">

<ItemTemplate >

<asp:DropDownLi st id="ddlproducto s" runat="server"> </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"></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", "{0:N0}%") %>'>

</asp:TextBox>

</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>



And my codebehind



Dim objconsultas As New LBDatos.consult as



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

If Not Page.IsPostBack Then

cargarproductos ()

cargardatagrid( )

End If

End Sub



Public Sub cargarproductos ()

Session("produc tos") = objconsultas.to dosproductoxCia (Session("idcom pania"))

End Sub



Private Sub cargardatagrid( )

Dim ds As DataSet

Dim dc1 As New DataColumn("Sub Total", System.Type.Get Type("System.De cimal")) 'i am assuming your stored proc does not contain a column SubTotal

Dim dc2 As New DataColumn("Can tidad", System.Type.Get Type("System.In t32"))

ds = objconsultas.pr oductoxCia(Sess ion("idcompania "))

ds.Tables(0).Co lumns.Add(dc2)

dc1.Expression = "Cantidad * Precioespecific o"

ds.Tables(0).Co lumns.Add(dc1)

dgpedidos.DataS ource = ds

dgpedidos.DataB ind()



End Sub









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.Da taSource = CType(Session(" productos"), DataSet)

ddlproductos.Da taTextField = "descripcio n"

ddlproductos.Da taValueField = "idproducto "

ddlproductos.Da taBind()

End If

End Sub







Private Sub dgpedidos_ItemC ommand(ByVal source As Object, ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles dgpedidos.ItemC ommand

If e.CommandName = "agregarproduct os" Then

Dim di As DataGridItem

di.





End If

End Sub



Nov 19 '05 #3

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

Similar topics

0
1538
by: Russ | last post by:
Hi, I have found myself wanting to use an HTMLSelect control instead of a DropDownList so that I can programatically set the item colours in the list (not possible with DropDownList due to attributes bug). My problem is I need to fire a server side event to execute some code when the user changes the selection. When I had a DropDownList I used the 'SelectedIndexChanged' event and it worked great - does anybody know how I can get the...
2
1386
by: Grey | last post by:
I have a dropdownlist control in ASP.NET form. But when I click on the control and attempt to change the option, there is nothing to happen to the server side, that is cannot trigger in action. How come of this happen??? Is it use "SelectedIndexChanged" for dealing the change options event?? Million thanks
3
1788
by: william | last post by:
Hi, I have a dropdownlist control and a few textbox on my web form. How can I update those textbox content when user select item from dropdownlist control? I really want to do this on client side so that don't need back to server. Thanks. william
7
5493
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the Repeater control, I've placed DropDownLists and CheckBoxes. When the user has updated the information, he/he clicks the submit button which is outside the scope of the Repeater control.
0
1587
by: ba | last post by:
I'm using asp.net 2.0 and am writing a webform using the formview control. The <%# Bind("") %> syntax makes sense for textboxes, but I cannot figure out how to bind a dropdown list to a column. The values to be entered from the dropdownlist are YES and NO. I want the source of the dropdown to be one of these two choices. When the record is in 'edit mode', I want the dropdown list selected
4
1890
by: Matt Jensen | last post by:
Howdy all Been searching and can't find a good answer to my problem. I've got a usercontrol 'banner' at the top of my page, and when the selection in the dropdown list changes I want the "host" webform/page to be reload so the data on it (in repeaters) is reloaded using a new value from the dropdownlist (and which btw is also stored in a session variable for later use). I'm not sure the best way to do this.
2
11060
by: Atreju | last post by:
Ok I got form within a c sharp page. Situation: On the form I have a drop downliwst and a textbox, the dropdownlist is populated with products and the textbox has a default vale of the product price. Problem: The first item prce in the dropdownlist is populated in the textbox. When I select another product from the dropdownlist the value within the
3
1911
by: S_K | last post by:
Hi, I have a list of 6 DropDownList boxes, from DropDownList1 to DropDownList6, and I'm changing the SelectedIndex of each using a foreach loop as follows: foreach(PaymentReqDisplay thispayment in listPaymentReqDisplay) { if ((string)thispayment.TaxType == "FIT") this.DropDownList1.SelectedIndex =
0
1832
by: Mel | last post by:
On Oct 23, 8:30 am, bruce barker <nos...@nospam.comwrote: Huh? Did you mean Listbox not DropDownList? The drop-down is working fine, it's the Listbox data that gets cleared after the drop-down list causes the postback.
0
9705
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
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
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...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
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...
1
7613
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
6847
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
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3809
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.