Home All Groups Group Topic Archive Search About
Author
23 Mar 2005 3:24 AM
Luis Esteban Valencia
my datagrid and code behind code  and help me if possible. I am making
asingle sales system and I need to add a new row with a linkbutton that
I put on the footer of the datagrid.

My datagrid has a product column (dropdownlist), quanitity( the user can
enter text here), price (not editable), taxes (not editable) and
subtotal, Price * quantity



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



This is my code behind if needed



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

Author
24 Mar 2005 5:13 PM
Victor_Carrión
Hola Luis, yo tengo el mismo problema, y Matias del foro de asp.net en español me dio una solucion: te la envio

Una de las formas que suelo emplear, si estoy usando databindig para el
manejo de la informacion.

Es tomar la fuente de datos de la grilla, esto te retornara una tabla, y a
la tabla adicionarle una nueva fila. Luego volver a llenar el datasource con
la nueva tabla.

Saludos,

--
Matias Iacono
Microsoft MVP ASP/ASP.net

  "Luis Esteban Valencia" <lu***@epm.net.co> escribió en el mensaje news:%23APe6f1LFHA.2136@TK2MSFTNGP14.phx.gbl...
  my datagrid and code behind code  and help me if possible. I am making asingle sales system and I need to add a new row with a linkbutton that I put on the footer of the datagrid.

  My datagrid has a product column (dropdownlist), quanitity( the user can enter text here), price (not editable), taxes (not editable) and subtotal, Price * quantity



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



  This is my code behind if needed



  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