codetoad.com
Home||ASP|ASP.Net|C++/C#|DHTML|HTML|Java|Javascript|Perl|VB|XML||CodeToadPlus!||Forums||RAM
Search Site:
Search Forums:
Shopping cart yaya at 06:50 on Tuesday, March 22, 2005

Hi. I have a problem regarding my shopping cart.When a user adds to cart, he/she should be able to edit the quantity without having to click on the edit button as used in datagrid. How do I go about doing it?

here are my codes:

private void Page_Load(object sender, System.EventArgs e)
{

string ProdID = Request.QueryString["ProductID"];
ArrayList cart;
cart = (ArrayList)Session["cart"];
if(cart==null)
cart = new ArrayList();
DataGrid1.DataSource = cart;
if(!IsPostBack)
{
if(Request.QueryString["ProductID"]!=null)
{
string id = Request.QueryString["ProductID"];
string prodName = Request.QueryString["ProductName"];
decimal price = decimal.Parse(Request.QueryString["Price"]);
//checks if product is already in cart
//bool found = false;
//foreach(cartItem citem in cart)
//{
// if(citem.ProdID.Equals(id))
// {
// found = true;
// citem.Qty++;
// }
//}
//if(!found)
cart.Add(new cartItem(id,prodName,"some desc",price,1));
Session["cart"] = cart;
}
DataGrid1.DataBind();
}
this.RefreshTotal();


}
private void RefreshTotal()
{
lblTotal.Text = this.GetTotal().ToString("C");
}
private decimal GetTotal()
{
ArrayList cart = (ArrayList)Session["cart"];
if(cart==null) return 0;
//calculates grand total
decimal grandTotal = 0;
foreach(cartItem citem in cart)
{
grandTotal += citem.UnitPrice * citem.Qty;
}
return grandTotal;
}

private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
DataGrid1.DataBind();
}

private void DataList1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{
TextBox txtQty;
txtQty = (TextBox)(e.Item.FindControl("Quantity"));
string newQuantity = txtQty.Text;
// Add code here to update the Quantity value of the data source
// using the newQuantity variable. Note taht newQuantity is a
// string and would have to be converted to a number.
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
matrix addition
Re: Storing data from HTML to Excel or TXT
Re: function within loop problem
Re: Ô‡´ò¥¯¥é¥Ö¤Ï ¥Æ©`¥é©`¥á¥¤¥É£ò£±£±¥¢¥¤¥¢¥ó ¤Î£··¬ ¤Ç¤¹
Re: Replace
Re: タイトリスト AP2アイアン 712�情�
Re: SMS from Perl using HTTP request
Re: Charl Schwartzel
Re: Adhyayan - Annual Student Conference and Online Coding Festival


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


Copyright codetoad.com 2001-2013