Solved

How to maintain enabled the update method on a GridView control

Posted on 2008-10-24
22
307 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

13 Experts available now in Live!

Get 1:1 Help Now