Solved

How to maintain enabled the update method on a GridView control

Posted on 2008-10-24
22
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

635 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