Click here to Skip to main content
14,326,442 members
Rate this:
Please Sign up or sign in to vote.
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 1:23am
Rajesh Anuhya 12-Jan-12 7:23am
Edited: added <Pre> tags

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100