62,249
社区成员




//修改商品数量及删除事件
protected void gv_cart_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "modi")
{
string proid = e.CommandArgument.ToString();
for (int i = 0; i < gv_cart.Rows.Count; i++)
{
CheckBox cb = (CheckBox)gv_cart.Rows[i].FindControl("cb_id");
if (cb != null)
{
if (cb.ToolTip == proid)
{
TextBox tb = (TextBox)gv_cart.Rows[i].FindControl("txt_num");
HiddenField hf = (HiddenField)gv_cart.Rows[i].FindControl("hfPrice");
Literal lab = (Literal)gv_cart.Rows[i].FindControl("lab_price");
double a = Convert.ToDouble(tb.Text);
double b = Convert.ToDouble(hf.Value);
double d_sum = a*b;
lab.Text = d_sum.ToString("#0.00");
//更改session中对应商品的数量
if (Session["MyCart"] != null)
{
Hashtable ht = new Hashtable();
ht = (Hashtable)Session["MyCart"];
ht[proid] = tb.Text;
Session["MyCart"] = ht;
}
}
}
}
GetSumPirce();//重新获取合计价格
}
if (e.CommandName == "del")
{
string proid = e.CommandArgument.ToString();
for (int i = 0; i < gv_cart.Rows.Count; i++)
{
CheckBox cb = (CheckBox)gv_cart.Rows[i].FindControl("cb_id");
if (cb != null)
{
if (cb.ToolTip==proid)
{
Hashtable ht = (Hashtable)Session["MyCart"];
ht.Remove(cb.ToolTip);
Session["MyCart"] = ht;
}
}
}
BindCart();
InitCart();
}
}