求ASP.NET购物车代码
3个回答
展开全部
页面:
<table width="80%">
<tr>
<td>
商品名称</td>
<td>
会员价格</td>
<td>
购买数量</td>
<td>
购买小计</td>
<td>
操作</td>
</tr>
<%
foreach (string s in dic.Values)
{
string[] temp = s.Split(',');
Response.Write("<tr>");
string newA = "<a href=\"usercart.aspx?deleteid=" + temp[0] + "\">删除</a>";
Response.Write(string.Format("<td>{0}<td>{1}<td>{2}<td>{3}<td>{4}</td>", temp[1], temp[2], temp[3], decimal.Parse(temp[2]) * int.Parse(temp[3]), newA));
Response.Write("</tr>");
}
}
%>
<tr>
<td colspan="6" style="height: 17px">
</td>
</tr>
</table>
页面cs文件:
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "";
if (Request.QueryString["deleteid"] != null)
{
string deleteid = Request.QueryString["deleteid"];
try
{
int id = int.Parse(deleteid); Dictionary<int, string> dic = Session["cart"] as Dictionary<int, string>;
if (dic.ContainsKey(id))
{
string[] temp = dic[id].Split(',');
int count = int.Parse(temp[3]);
if (count > 1)
{
temp[3] = string.Format("{0}", count - 1);
dic.Remove(id);
dic.Add(id, string.Format("{0},{1},{2},{3}", temp[0], temp[1], temp[2], temp[3]));
Session["cart"] = dic;
Label1.Text = "<script>alert('删除成功!');</script>";
// Response.Write();
}
else
{
dic.Remove(id);
Session["cart"] = dic;
Label1.Text = "<script>alert('删除成功!');</script>";
//Response.Write("<script>alert('删除成功!');</script>");
}
}
}
catch (Exception)
{
}
}
}
<table width="80%">
<tr>
<td>
商品名称</td>
<td>
会员价格</td>
<td>
购买数量</td>
<td>
购买小计</td>
<td>
操作</td>
</tr>
<%
foreach (string s in dic.Values)
{
string[] temp = s.Split(',');
Response.Write("<tr>");
string newA = "<a href=\"usercart.aspx?deleteid=" + temp[0] + "\">删除</a>";
Response.Write(string.Format("<td>{0}<td>{1}<td>{2}<td>{3}<td>{4}</td>", temp[1], temp[2], temp[3], decimal.Parse(temp[2]) * int.Parse(temp[3]), newA));
Response.Write("</tr>");
}
}
%>
<tr>
<td colspan="6" style="height: 17px">
</td>
</tr>
</table>
页面cs文件:
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "";
if (Request.QueryString["deleteid"] != null)
{
string deleteid = Request.QueryString["deleteid"];
try
{
int id = int.Parse(deleteid); Dictionary<int, string> dic = Session["cart"] as Dictionary<int, string>;
if (dic.ContainsKey(id))
{
string[] temp = dic[id].Split(',');
int count = int.Parse(temp[3]);
if (count > 1)
{
temp[3] = string.Format("{0}", count - 1);
dic.Remove(id);
dic.Add(id, string.Format("{0},{1},{2},{3}", temp[0], temp[1], temp[2], temp[3]));
Session["cart"] = dic;
Label1.Text = "<script>alert('删除成功!');</script>";
// Response.Write();
}
else
{
dic.Remove(id);
Session["cart"] = dic;
Label1.Text = "<script>alert('删除成功!');</script>";
//Response.Write("<script>alert('删除成功!');</script>");
}
}
}
catch (Exception)
{
}
}
}
2011-03-10
展开全部
八百块给你写一个 QQ869067911
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询