且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从产品购物车中删除该行,我正在使用gridview来显示产品

更新时间:2023-10-25 15:08:10



有很多实现方法.

我的建议之一是将选定的值存储在会话变量中,然后您可以在用户付款之前随时删除或添加.

在这里,我提供了用于将数据存储在会话变量中的示例代码

Hi,

there are so many ways to implement that .

one of my suggestion is store selected values in session variable then you can delete or add when ever you want before user make payment.

Here I''m providing sample code for to store data in session variable

   //On click of AddToCart 
  DataTable dt=new DataTable(); 
  if(Session["Cart"].tostring()=="")
{
     dt.columns.Add("itemid");
     dt.columns.Add("itemcost");
     dt.columns.Add("itemcount");
}
else
{
   dt=(DataTable)Session["Cart"];
}
   addData(dt,itemid,itemcost,itemcount);
   Session["Cart"]=dt;
 //dt is datatable object which holds the selected items information.



在上面的代码中,addData()是自定义方法,可将行添加到dt

在这里,您可以随时从该数据中删除行



In the above code addData() is custom method to add row to dt

Here you can delete row from that data whenever you want

 //On delete click
 DataTable dt=new DataTable(); 
 dt=(DataTable)Session["Cart"];
 dr=dt.newrow();

 dr[0]=itemid;//Here itemid means which item you want to delete come from delete button argument
dr[1]=itemcost;
dr[2]=itemcount;
    dt.Rows.Remove(dr);
  Session["Cart"]=dt;



这仅是示例,您可以实现此功能以实现您的要求.

***的



This just for sample you can implement this for achieve your requirement.

All the Best