By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

How to change row data when dropdownlist changes?

P: n/a
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="True" AutoGenerateColumns="False">
<ItemStyle CssClass="registros"></ItemStyle>
<HeaderStyle CssClass="titulostablas"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Eliminar"
CommandName="Delete"></asp:ButtonColumn>
<asp:TemplateColumn HeaderText="Producto">
<ItemTemplate>
<asp:DropDownList id="ddlproductos" runat="server"></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"></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",
"{0:N0}%") %>'>
</asp:TextBox>
</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>

And my codebehind

Dim objconsultas As New LBDatos.consultas

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

If Not Page.IsPostBack Then

cargarproductos()

cargardatagrid()

End If

End Sub

Public Sub cargarproductos()

Session("productos") =
objconsultas.todosproductoxCia(Session("idcompania "))

End Sub

Private Sub cargardatagrid()

Dim ds As DataSet

Dim dc1 As New DataColumn("SubTotal",
System.Type.GetType("System.Decimal")) 'i am assuming your stored proc
does not contain a column SubTotal

Dim dc2 As New DataColumn("Cantidad",
System.Type.GetType("System.Int32"))

ds = objconsultas.productoxCia(Session("idcompania"))

ds.Tables(0).Columns.Add(dc2)

dc1.Expression = "Cantidad * Precioespecifico"

ds.Tables(0).Columns.Add(dc1)

dgpedidos.DataSource = ds

dgpedidos.DataBind()

End Sub



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

ddlproductos.DataTextField = "descripcion"

ddlproductos.DataValueField = "idproducto"

ddlproductos.DataBind()

End If

End Sub



Private Sub dgpedidos_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
dgpedidos.ItemCommand

If e.CommandName = "agregarproductos" Then

Dim di As DataGridItem

di.

End If

End Sub


Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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**************@TK2MSFTNGP14.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="True" AutoGenerateColumns="False">

<ItemStyle CssClass="registros"></ItemStyle>

<HeaderStyle CssClass="titulostablas"></HeaderStyle>

<Columns>

<asp:ButtonColumn Text="Eliminar" CommandName="Delete"></asp:ButtonColumn>

<asp:TemplateColumn HeaderText="Producto">

<ItemTemplate>

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

</asp:TextBox>

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



And my codebehind



Dim objconsultas As New LBDatos.consultas



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

If Not Page.IsPostBack Then

cargarproductos()

cargardatagrid()

End If

End Sub



Public Sub cargarproductos()

Session("productos") = objconsultas.todosproductoxCia(Session("idcompania "))

End Sub



Private Sub cargardatagrid()

Dim ds As DataSet

Dim dc1 As New DataColumn("SubTotal", System.Type.GetType("System.Decimal")) 'i am assuming your stored proc does not contain a column SubTotal

Dim dc2 As New DataColumn("Cantidad", System.Type.GetType("System.Int32"))

ds = objconsultas.productoxCia(Session("idcompania"))

ds.Tables(0).Columns.Add(dc2)

dc1.Expression = "Cantidad * Precioespecifico"

ds.Tables(0).Columns.Add(dc1)

dgpedidos.DataSource = ds

dgpedidos.DataBind()



End Sub









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

ddlproductos.DataTextField = "descripcion"

ddlproductos.DataValueField = "idproducto"

ddlproductos.DataBind()

End If

End Sub







Private Sub dgpedidos_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgpedidos.ItemCommand

If e.CommandName = "agregarproductos" Then

Dim di As DataGridItem

di.





End If

End Sub



Nov 19 '05 #2

P: n/a
How would it be in code?
"Jignesh Desai" <ji***********@hotmail.com> escribió en el mensaje news:Oo**************@TK2MSFTNGP09.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**************@TK2MSFTNGP14.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="True" AutoGenerateColumns="False">

<ItemStyle CssClass="registros"></ItemStyle>

<HeaderStyle CssClass="titulostablas"></HeaderStyle>

<Columns>

<asp:ButtonColumn Text="Eliminar" CommandName="Delete"></asp:ButtonColumn>

<asp:TemplateColumn HeaderText="Producto">

<ItemTemplate>

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

</asp:TextBox>

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



And my codebehind



Dim objconsultas As New LBDatos.consultas



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

If Not Page.IsPostBack Then

cargarproductos()

cargardatagrid()

End If

End Sub



Public Sub cargarproductos()

Session("productos") = objconsultas.todosproductoxCia(Session("idcompania "))

End Sub



Private Sub cargardatagrid()

Dim ds As DataSet

Dim dc1 As New DataColumn("SubTotal", System.Type.GetType("System.Decimal")) 'i am assuming your stored proc does not contain a column SubTotal

Dim dc2 As New DataColumn("Cantidad", System.Type.GetType("System.Int32"))

ds = objconsultas.productoxCia(Session("idcompania"))

ds.Tables(0).Columns.Add(dc2)

dc1.Expression = "Cantidad * Precioespecifico"

ds.Tables(0).Columns.Add(dc1)

dgpedidos.DataSource = ds

dgpedidos.DataBind()



End Sub









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

ddlproductos.DataTextField = "descripcion"

ddlproductos.DataValueField = "idproducto"

ddlproductos.DataBind()

End If

End Sub







Private Sub dgpedidos_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dgpedidos.ItemCommand

If e.CommandName = "agregarproductos" Then

Dim di As DataGridItem

di.





End If

End Sub



Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.