Final Checkout - Data not getting passed so the Page_Load is getting fired in Checkout.asp.cs

Sep 25, 2010 at 12:02 AM

BTW: the tutorial is great!   But having a problem and could use some help.  I've been following along the tutorial and what should be happening according to the tutorial is a) select items  b) select "final Check out" c) goes to "login"  d) back to "final check out"  e) Submit  f) order complete.

However after logging in c) and back to final check out (d), when i press "final Check out" I get "your shopping cart is empty"

The data's getting saved to the "ShoppingCart" table but somehow the data isn't getting passed so in the "checkout.aspx.cs" file the "Page_Load" method is getting fired...

   protected void Page_Load(object sender, EventArgs e)
       {
        CheckOutHeader.InnerText = "Your Shopping Cart is Empty";
        LabelCartHeader.Text = "";
        CheckoutBtn.Visible = false;
       }

...so my result is "Your Shopping Cart is Empty"

 

What should be getting fired is the  "MyList_RowDataBound" (below) method but it's not....

protected void MyList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TailspinSpyworks.Data_Access.ViewCart myCart = new Data_Access.ViewCart();
                myCart = (TailspinSpyworks.Data_Access.ViewCart)e.Row.DataItem;
                _CartTotal += myCart.UnitCost * myCart.Quantity;
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                if (_CartTotal > 0)
                {
                   CheckOutHeader.InnerText = "Review and Sumbit Your Order";
                    LabelCartHeader.Text = "Please Make Sure Correct";
                    CheckoutBtn.Visible = true;
                    e.Row.Cells[5].Text = "Total: " + _CartTotal.ToString("C");
                }
            }
        }



QUESTION / PROBLEM:  Why is the data not getting passed to the "MyList_RowDataBound"?

 

Thanks for any help here.

 

 

Sep 26, 2010 at 5:43 PM

Actually it should fire up and run as it should, it does with my versions, but I need to see your code for that page before I can tell what is happening, maybe you are missing to declare the global in the checkout.aspx.cs file

decimal _CartTotal = 0;

Sep 27, 2010 at 8:27 AM

@basba...

 

Debugger shows the "_CartTotal = 0"  Here's my checkout.aspx.cs file as of lesson "Popular Products Control" from the tutorial...



CHECKOUT.ASPX.CS
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using MyTailspinSpyworks;

namespace MyTailspinSpyworks
{
    public partial class CheckOut : System.Web.UI.Page
    {
        decimal _CartTotal = 0;

        protected void Page_Load(object sender, EventArgs e)
       {
          CheckOutHeader.InnerText = "Your Shopping Cart is Empty";
        LabelCartHeader.Text = "";
        CheckoutBtn.Visible = false;
       }

        protected void CheckoutBtn_Click(object sender, ImageClickEventArgs e)
        {
            MyShoppingCart usersShoppingCart = new MyShoppingCart();
            if (usersShoppingCart.SubmitOrder(User.Identity.Name) == true)
            {
                CheckOutHeader.InnerText = "Thank You, Order Complete";
                Message.Visible = false;
                CheckoutBtn.Visible = false;
            }
            else
            {
                CheckOutHeader.InnerText = "Sorry - your order submission failed - please try again";
            }
        }
        
        protected void MyList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                MyTailspinSpyworks.Data_Access.ViewCart myCart = new Data_Access.ViewCart();
                myCart = (MyTailspinSpyworks.Data_Access.ViewCart)e.Row.DataItem;
                _CartTotal += myCart.UnitCost * myCart.Quantity;
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                if (_CartTotal > 0)
                { 
                   CheckOutHeader.InnerText = "Review and Sumbit Your Order";
                    LabelCartHeader.Text = "Please Make Sure Correct";
                    CheckoutBtn.Visible = true;
                    e.Row.Cells[5].Text = "Total: " + _CartTotal.ToString("C");
                }
            }
        }
    }
}
 
-------------------------------
In debugger I'm seeing the values for the asp:GridView control ID="MyList" such as ...
-  DataKeyNames {string[3]} string[]
  [0] "ProductID" string
  [1] "UnitCost" string
  [2] "Quantity" string
  AutoGenerateColumns false bool
 
etc....
but I don't see "OnRowDataBound" property listed, would that be listed as well?
 
The Gridview control in the "CheckOut.aspx" page is set as follows..

<

asp:GridView ID="MyList" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID,UnitCost,Quantity" DataSourceID="EDS_Cart"

 

CellPadding="4" GridLines="Vertical" CssClass="CartListItem" OnRowDataBound="MyList_RowDataBound" ShowFooter="True">

 

 

 

 --------------

  

Thanks for your help :)