Solved

How to maintain enabled the update method on a GridView control

Posted on 2008-10-24
22
312 Views
Last Modified: 2013-11-07
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
Comment
Question by:dimensionav
  • 13
  • 9
22 Comments
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22797224
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
 

Author Comment

by:dimensionav
ID: 22808138
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
 

Author Comment

by:dimensionav
ID: 22808142
The ObjectDataSource is connected to the BLL
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22813626
The only thing is that your button or imageButton must have:

-To enable editing CommandName="Edit"
-To enable updating CommandName="Update"
0
 

Author Comment

by:dimensionav
ID: 22816088
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
 

Author Comment

by:dimensionav
ID: 22816105
Sorry I said selecting instead of Updating
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22816675
To enable selecting CommandName="Select"
0
 

Author Comment

by:dimensionav
ID: 22818801
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
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22822847
Can you put your grid code?
0
 

Author Comment

by:dimensionav
ID: 22825072
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
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22825351
Your button is outside the grid... you must put your button into a column inside the grid
0
 

Author Comment

by:dimensionav
ID: 22825965
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
 
LVL 15

Accepted Solution

by:
jorge_toriz earned 500 total points
ID: 22826154
Catch your click event of your button and then call odsCarrito.Update();
0
 

Author Comment

by:dimensionav
ID: 22829335
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
 

Author Comment

by:dimensionav
ID: 22855935
Jorge

Should I post my last question as a new one?

Thanks
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22882771
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
 

Author Comment

by:dimensionav
ID: 22905600
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
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22952912
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
 

Author Comment

by:dimensionav
ID: 22953016
As you said, Only once would be better.
0
 

Author Comment

by:dimensionav
ID: 22994407
Any comments Jorge?

Thanks
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 22995751
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
 

Author Closing Comment

by:dimensionav
ID: 31509690
Thank you for all your patience and the comprehensive information.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now