技术开发 频道

一个购物车中修改商品数量的实列


【IT168技术文档】

//在这个实列中,只要你修改某件商品的数量,就会触发一个TextChanged事件,在这个事件中它会遍历datalist中的每一行,然后得到每一行中的单价,和数量,最后把算出的结果附给总价,每行都这么做。就达到更新的目的了。。 protected void txtCount_TextChanged(object sender, EventArgs e) { double theTotal = 0; for (int i = 0; i < this.DataList1.Items.Count; i++) { string value = ((Label)this.DataList1.Items[i].FindControl("price")).Text; double price = Convert.ToDouble(value); int count = Convert.ToInt32(((TextBox)this.DataList1.Items[i].FindControl("txtCount")).Text); ((Label)this.DataList1.Items[i].FindControl("total")).Text = Convert.ToString(price * count); theTotal = theTotal + price * count; } this.totalPrice.Text = theTotal.ToString(); }
0
相关文章