Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2008, 07:04 AM
Registered User
 
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Shopping Cart - Grid View Question

I'm trying to change the Grid View in the shopping cart so that the user can alter the quantity without having to first click an edit button - any pointers on how to do this.

Your book is much appreciated by me and I've implemented the web shop in c#

Many thanks

John Elliott

 
Old March 29th, 2008, 04:14 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi John,

Glad you like the book. Would you be willing to share your C# version of the code with other Wrox forum visitors?

The problem with the solution you are proposing is that it's no longer single row based; e.g. a user may now be able to update multiple rows at once (depending on how you implement it). This means it's no longer easy to let the GridView handle the Cart update automatically (although still possible). To force the GridView and the Cart to be updated, you could add an Update Cart button that loops through the items in the cart and updates them. Here's a break down of how you could implement it:

1. Move the DropDownList for the quantity into the ItemTemplate.

2. Remove the AutoPostBack and OnSelectedIndexChanged attributes from this drop down so it becomes a simple DropDownList.

3. Below the GridView add a new button called btnUpdate. Set its Text to something like Update Cart.

4. Double click the button in Design View and add the following code:
Code:
Protected Sub btnUpdate_Click(ByVal sender As Object, _
           ByVal e As System.EventArgs) Handles Button1.Click

  For Each myRow As GridViewRow In GridView1.Rows

    ' Find the Id of the current product
    Dim key As Guid = New Guid(GridView1.DataKeys(myRow.DataItemIndex).Value.ToString())

    ' Find the DropDownList with the quanity (old or new)
    Dim myControl As DropDownList = myRow.FindControl("lstQuantity")

    ' Get the chosen quantity
    Dim newQuantity As Integer = Convert.ToInt32(myControl.SelectedValue)

    ' Update each product by calling the Update method, just as the ODS used to do
    ShopManager.ShoppingCart.Update(newQuantity, key)
  Next

  ' Tell the world the cart has changed
  RaiseEvent CartUpdated(sender, New System.EventArgs())

End Sub
It's VB.NET code only, but if you were able to convert the entire Shop, I don't think this poses a problem. If it does, let me know and I'll rewrite it in C#.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
shopping cart keyvanjan Classic ASP Basics 1 January 9th, 2007 10:16 PM
Shopping Cart seannie ASP.NET 2.0 Basics 0 December 12th, 2006 10:28 AM
Shopping cart help rsm42 ASP.NET 1.0 and 1.1 Basics 3 December 9th, 2006 06:09 AM
shopping cart xipnl BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 June 10th, 2005 07:00 PM
shopping cart isheikh BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 8th, 2004 04:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.