[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

How to maintain enabled the update method on a GridView control

HI

I have developed a web application that it works as a shopping cart, at this moment the application shows a GridView bound to a collection with the selected products, the customer can update the quantity by clicking on "update" method of the control per each item.

What I want is to keep Update status permanently while the customer is viewing the shopping cart in order to avoid one step, How could I do that?

Thanks in advance
0
dimensionav
Asked:
dimensionav
  • 13
  • 9
1 Solution
 
jorge_torizResearch & Development ManagerCommented:
In your ItemTemplate add a textBox that will keep the actual amount of product, and then, add another button to update all the amounts at the same time
<asp:GridView id="gvCart" runat="server" AutoGenerateColumns="false" DataSourceID="sdsMyCart" DataKeyNames="ProductId">
    <Columns>
        <asp:BoundField DataField="Name" ReadOnly="true"/>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:TextBox id="txtQty" runat="server"
Text='<%# DataBinder.Eval(Container.DataItem, "Qty") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
 
--Add another button to update all the quantities at the same time
 
<asp:Button id="cmdUpdate" runat="server" Text="Update"/>

Open in new window

0
 
dimensionavAuthor Commented:
HI Jorge

As you can see I am using an ObjectDataSource to bound data, how would I link the update button in order that triggers the update event:

            <asp:ObjectDataSource id="odsCarrito" runat="server"
                                  OnSelecting="odsCarrito_Selecting"
                                  OnUpdating="odsCarrito_Updating"
                                  TypeName="DAV.TiendaEnLinea.v1.BusinessLogicLayer.BLLCarritoDeCompras"
                                  SelectMethod="ObtieneContenidoDeCarrito"
                                  UpdateMethod="ActualizaContenidoDeCarrito">
                <SelectParameters>
                    <asp:Parameter Name="CurrentSession" Type="Object"  />
                </SelectParameters>

            <UpdateParameters>
                <asp:Parameter Name="CurrentSession" Type="Object"/>
                <asp:Parameter Name="Id_Producto" Type="int32" ></asp:Parameter>                
                <asp:Parameter Name="Cantidad" Type="int32"></asp:Parameter>
            </UpdateParameters>
               
            </asp:ObjectDataSource>
0
 
dimensionavAuthor Commented:
The ObjectDataSource is connected to the BLL
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jorge_torizResearch & Development ManagerCommented:
The only thing is that your button or imageButton must have:

-To enable editing CommandName="Edit"
-To enable updating CommandName="Update"
0
 
dimensionavAuthor Commented:
HI Jorge

This is my button:

        <asp:Button ID="btnActualizar" runat="server" Text="Actualizar" CommandName="Update" />

And this is the selecting event:

    Protected Sub odsCarrito_Updating(ByVal source As Object, ByVal e As ObjectDataSourceMethodEventArgs)
        e.InputParameters("CurrentSession") = CurrentSession
    End Sub

But using the debuger I have noticed that the updating event is never triggered.
0
 
dimensionavAuthor Commented:
Sorry I said selecting instead of Updating
0
 
jorge_torizResearch & Development ManagerCommented:
To enable selecting CommandName="Select"
0
 
dimensionavAuthor Commented:
As I said before using the debuger I have noticed that the updating event is never triggered.:
<asp:Button ID="btnActualizar" runat="server" Text="Actualizar" CommandName="Update" />

Do you see anything wrong?

Thanks Jorge
0
 
jorge_torizResearch & Development ManagerCommented:
Can you put your grid code?
0
 
dimensionavAuthor Commented:
There is GridView, Button and DataSource:

            <asp:GridView runat="server"
                ID="gvProductos"
                AutoGenerateColumns="False"
                RowStyle-CssClass="LineaDeContenidoCarrito" CellPadding="5"
                AllowSorting="True"
                DataSourceID="odsCarrito"
                DataKeyNames="Id_Producto"
                ShowFooter="true">
                <columns>

                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:TextBox id="tbCantidad" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Cantidad") %>'></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>                
                    <asp:BoundField DataField="Codigo" ItemStyle-Wrap="false" ItemStyle-Width="68" ReadOnly="true"  ></asp:BoundField>
                    <asp:BoundField DataField="Titulo" ItemStyle-Wrap="false" ItemStyle-Width="206" ReadOnly="true"></asp:BoundField>
                    <asp:BoundField DataField="PrecioLista" ItemStyle-Wrap="false" ItemStyle-Width="97" ReadOnly="true" HtmlEncode="false" DataFormatString="{0:C2}" ItemStyle-HorizontalAlign="Right"></asp:BoundField>

                    <asp:TemplateField ItemStyle-Wrap="false" ItemStyle-Width="102" ItemStyle-HorizontalAlign="Right">
                        <ItemTemplate>
                          <asp:Label ID="lbSubtotal" Runat="Server"
                                     Text='<%# String.Format("{0:C2}", Eval("Cantidad") * Eval("PrecioLista")) %>' />
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:CommandField ItemStyle-Wrap="false" ItemStyle-Width="35"
                        DeleteText="Eliminar"
                        ShowDeleteButton="True"/>
                </columns>
                <RowStyle CssClass="LineaDeContenidoCarrito" />
                <EmptyDataTemplate>
                    <span class="NegroN12">
                        ! Por el momento tu carrito de compras aparece vacío ¡ <br /><br />
                        Si deseas agregar productos ingresa al CATALOGO.<br /><br />
                        Si no tienes cuenta o no has iniciado sesion ingresa a TU CUENTA para mas detalles.
                       
                    </span>
              </EmptyDataTemplate>
 
            </asp:GridView>
       
        <asp:Button ID="btnActualizar" runat="server" Text="Actualizar" CommandName="Update" />

            <asp:ObjectDataSource id="odsCarrito" runat="server"
                                  OnSelecting="odsCarrito_Selecting"
                                  OnUpdating="odsCarrito_Updating"
                                  TypeName="DAV.TiendaEnLinea.v1.BusinessLogicLayer.BLLCarritoDeCompras"
                                  SelectMethod="ObtieneContenidoDeCarrito"
                                  UpdateMethod="ActualizaContenidoDeCarrito">
                <SelectParameters>
                    <asp:Parameter Name="CurrentSession" Type="Object"  />
                </SelectParameters>

            <UpdateParameters>
                <asp:Parameter Name="CurrentSession" Type="Object"/>
                <asp:Parameter Name="Id_Producto" Type="int32" ></asp:Parameter>                
                <asp:Parameter Name="Cantidad" Type="int32"></asp:Parameter>
            </UpdateParameters>
               
            </asp:ObjectDataSource>
0
 
jorge_torizResearch & Development ManagerCommented:
Your button is outside the grid... you must put your button into a column inside the grid
0
 
dimensionavAuthor Commented:
You´re right !

Is there any way to show just one button and no one per each row, I have attached an image about how it looks like.

Thanks.

-027.jpg
0
 
jorge_torizResearch & Development ManagerCommented:
Catch your click event of your button and then call odsCarrito.Update();
0
 
dimensionavAuthor Commented:
You got It!, Just one more question Jorge:

After clicking the update Button I need to know the new values of the "Quantity" fields that are bound to the textbox control, how could I pass them as a Update Parameter ? where I get them from ?

Thanks again
0
 
dimensionavAuthor Commented:
Jorge

Should I post my last question as a new one?

Thanks
0
 
jorge_torizResearch & Development ManagerCommented:
Sorry for the lately response... I was outside and without internet access.

In your updating event you must iterate through your rows and then find your textBox and take its value out.

Use the FindControl function of the row
0
 
dimensionavAuthor Commented:
Considering that I need to send this values to BLL as a parameter which option would be better?:

A. Create an array on the UI
B. Make a reference to a control ? (How?, by the way).

Thanks again
0
 
jorge_torizResearch & Development ManagerCommented:
Do you want to call the update method of your BLL for each value of your textBox of your grid?

or

Do you want to call the update methor of your BLL only once with all the values?

I would prefer to call only once.
0
 
dimensionavAuthor Commented:
As you said, Only once would be better.
0
 
dimensionavAuthor Commented:
Any comments Jorge?

Thanks
0
 
jorge_torizResearch & Development ManagerCommented:
Iterate through your gridView rows to take out the textBox values and store them in an array to pass it as a parameter to your BLL
0
 
dimensionavAuthor Commented:
Thank you for all your patience and the comprehensive information.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 13
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now