Click here to Skip to main content
15,848,157 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"];


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
Updated 12-Jan-12 2:23am
Rajesh Anuhya 12-Jan-12 7:23am    
Edited: added <Pre> tags

1 solution

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

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

Obviously, the parent of the parent of the button is not a DetailsViewRow.
Share this answer
RashdSiddique 12-Jan-12 7:39am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900