日期:2014-05-19  浏览次数:20428 次

如何删除购物车内商品。
如题。购物车是用DataGrid.第一列绑定商品id.最后一列绑定按纽-删除。如何实现点击删除,就把购物车内的商品去掉?谢谢·

------解决方案--------------------
for (int i = 0; i < dataGrid.SelectedRows.Count; i++)
{
//同时删除掉TUserAccount,TNoticeUser,TNoticeGroupLink中相关联的数据。
string UserID = dataGridView1.Rows[dataGrid.SelectedRows[i].Index].Cells[ "UserID "].Value.ToString();
string sql = string.Format( "delete from TUserAccount where UserID = '{0} ' "+
" delete from TNoticeUser where UserID = '{1} ' "+
" delete from TNoticeUser where UserID = '{2} ' ", UserID, UserID, UserID);

dtfactory.UpDataRecord(sql);

}
------解决方案--------------------
/// <summary>
/// DATAGRID的删除按钮
/// </summary>

private void dtgList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
textCD tcd=new textCD();
string fvt_strMoney = " ";
int fvt_intWeight = 0;
DataTable DT_MyCar = (DataTable)Session[ "mytable "];//将Session中的值赋给新定义的DataTable

TextBox TB_NewNum = (TextBox)e.Item.FindControl( "Num ");

for(int i=0;i <DT_MyCar.Rows.Count;i++)
{
if(DT_MyCar.Rows[i][ "商品ID "].ToString()==e.Item.Cells[0].Text)
{
fvt_strMoney = DT_MyCar.Rows[i][ "金额 "].ToString();
fvt_intWeight = Convert.ToInt32(DT_MyCar.Rows[i][ "重量 "]);
}
}

this.lbl_BuyNum.Text = Convert.ToString(Convert.ToInt32(this.lbl_BuyNum.Text) - Convert.ToInt32(tcd.ToDBC(TB_NewNum.Text)));

this.lbl_AllMoney.Text = Convert.ToString(Convert.ToDecimal(this.lbl_AllMoney.Text) - Convert.ToDecimal(fvt_strMoney));

this.lbl_Weight.Text = Convert.ToString(Convert.ToInt32(this.lbl_Weight.Text) - fvt_intWeight);

DT_MyCar.Rows[Convert.ToInt32(e.Item.ItemIndex)].Delete();//执行删除行

DT_MyCar.AcceptChanges();

Session[ "mytable "] = DT_MyCar;//将最新的结果返还给Session

this.dtgList.DataSource = DT_MyCar;//绑定DataGrid的数据源

this.dtgList.DataBind();
Page_Load(null,null);
}