对购物车的怀疑 [英] Doubt for shopping cart

查看:66
本文介绍了对购物车的怀疑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我正在制作一个应用程序,用于构建购物车.
用户将选择产品,然后单击添加到购物车"按钮.该产品将被添加到购物车.详细信息将从detailview发送,我直接从数据库中显示产品的详细信息.
用于将详细信息发送到购物车的代码是

Hi friends i am making an application in which i am building a shopping cart.
User will select the product and click on "Add to cart" button.The product will be added to shopping cart.Details will be send from a detailview in which i am showing the details of the product directly from the database.
The code for sending the details to the shopping cart is

DetailsViewRow dr1 = (DetailsViewRow)((Button)sender).Parent.Parent;
        string name = ((Label)dr1.FindControl("Label3")).Text;
        string price = ((Label)dr1.FindControl("Label2")).Text;
        string id = ((Label)dr1.FindControl("Label4")).Text;
        string quantity = ((TextBox)dr1.FindControl("txtQuantity")).Text;
        LineItem item1 = new LineItem(int.Parse(id), name, double.Parse(price), int.Parse(quantity));
        Invoice ord1 = (Invoice)Session["basket"];
        ord1.AddItem(item1);

        Server.Transfer("ShoppingCart.aspx");


但我遇到错误

无法将类型为"System.Web.UI.HtmlControls.HtmlForm"的对象转换为类型为"System.Web.UI.WebControls.DetailsViewRow".

我试图解决它,但是没有运气.
谁能帮我


but i am getting an error

Unable to cast object of type ''System.Web.UI.HtmlControls.HtmlForm'' to type ''System.Web.UI.WebControls.DetailsViewRow''.

I tried to solve it but with no luck.
Can any one help me

推荐答案

您调试了吗?如果有的话,您会清楚地看到这是问题所在.

Have you debugged? If you had you would clearly see this is the problem.

DetailsViewRow dr1 = (DetailsViewRow)((Button)sender).Parent.Parent;



显然,按钮的父级的父级不是DetailsViewRow.



Obviously, the parent of the parent of the button is not a DetailsViewRow.


这篇关于对购物车的怀疑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆