Hello all, 

 

      I am stuck. I have been asked to write a Shopping Cart class that uses
an object from an Events class to hold a user's shopping cart in memory. The
SQL guy doesn't want to have a Shopping Cart table in SQL Server. Basically,
I am pulling two session variables (clientID & regID) and a querystring
variable (eid -- "eventID") to make the cart client/user/event specific. I
am having problems doing two things (to begin with). First, populating the
in memory DataTable correctly with the GetEventsByID (short clientID, short
eventID) object is not working. Second, I can't get it to display in a
datagrid. It compiles in VS.NET 2003 fine, but going to the page gives me a
Stack Overflow error. I haven't even got to the part where the quantity or
in memory DataTable can be manipulated. If anyone wants the .aspx page that
has the DataGrid listing, I can provide that as well.

 

Here's what I have(code-behind):

 

            protected System.Web.UI.WebControls.DataGrid dgCart;

 

            DataTable Cart;

            DataView CartView;

            short shtSsnClientID;

            short shtQryEventID;

 

            private void Page_Load(Object sender, EventArgs e) 

            {

 

                  shtSsnClientID    = Convert.ToInt16(Session["clientID"]);

                  shtQryEventID     =
Convert.ToInt16(Request.QueryString["eid"]);

                  

                  if (Session["rLMS_Cart"] == null)     

                  {

                        Cart = new DataTable();

                        Cart.Columns.Add(new DataColumn("Qty",
typeof(string)));

                        Cart.Columns.Add(new DataColumn("Item",
typeof(string)));

                        Cart.Columns.Add(new DataColumn("Price",
typeof(string)));

                        Session["rLMS_Cart"] = Cart;

 

                        rLMS.classes.Event cartEvent = new
rLMS.classes.Event();

                        cartEvent.GetEventByID(shtSsnClientID,
shtQryEventID);

 

                        // first load -- populate with data from browseEvent
register click.

                        int i=1;

                        

                        DataRow dr = Cart.NewRow();

                        dr[0] = ((int)(i%2)+1).ToString();

                        dr[1] = cartEvent.Event_Description.ToString();

                        dr[2] = cartEvent.Event_ListPrice.ToString(); 

                        Cart.Rows.Add(dr);

                        

                  }

                  else 

                  {

                        Cart = (DataTable)Session["rLMS_Cart"];

                  }

 

                  CartView = new DataView(Cart);

                  CartView.Sort = "Item";

                  if (!IsPostBack) 

                  {

                        BindGrid();

                  }

            }

 

            public void dgCart_Edit(Object sender, DataGridCommandEventArgs
e) 

            {

                  dgCart.EditItemIndex = (int)e.Item.ItemIndex;

                  BindGrid();

            }

 

            public void dgCart_Cancel(Object sender,
DataGridCommandEventArgs e) 

            {

                  dgCart.EditItemIndex = -1;

                  BindGrid();

            }

 

            public void dgCart_Update(Object sender,
DataGridCommandEventArgs e) 

            {

                  // For bound columns the edited value is stored in a
textbox,

                  // and the textbox is the 0th element in the column's cell

                  string item = e.Item.Cells[1].Text;

                  string qty = ((System.Web.UI.WebControls.TextBox)

                        e.Item.Cells[2].Controls[0]).Text;

                  string price = e.Item.Cells[3].Text;

 

                  // in-memory DataTable, delete the old row and replace it
with a new one

                  CartView.RowFilter = "Event=";

                  if (CartView.Count > 0) 

                  {

                        //item exists in cart

                        CartView.Delete(0);

                  }

                  CartView.RowFilter = "";

 

                  //add new entry

                  DataRow dr = Cart.NewRow();

                  dr[0] = qty;

                  dr[1] = item;

                  dr[2] = price;

                  Cart.Rows.Add(dr);

 

                  dgCart.EditItemIndex = -1;

                  BindGrid();

            }

 

            public void BindGrid() 

            {

                  dgCart.DataSource = CartView;

                  dgCart.DataBind();

            }

 

Any suggestions? If I am completely on the wrong track, please let me know.
I am still a beginner for the most part.

 

Thanks in advance, 

Ryan.

 


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.0 - Release Date: 3/21/2005




[Non-text portions of this message have been removed]



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to