krisel 0 Newbie Poster

can someone please help me.. im working on a nested gridview where the parent gridview displays the majorcategory while the childgridview displays the material, unit cost, quantity, total etc...my problem is whenever i clicked on the compute button it does not compute subtotals..meaning it continuously add the value. i need to first compute the subtotal per childgridview and then add all the subtotal to get the grandtotal..here is my code in the button click...please help..it s urget...our thesis deadline is fast approaching..i need to finish this functionality immediately..thanks in advance

protected void BtnCompute_Click(object sender, EventArgs e)
    {

        foreach (GridViewRow parentgrdview in GridView1.Rows)
        {
            GridView childgrdview = (GridView)parentgrdview.FindControl("GridView2");
            GridViewRow footerRow = childgrdview.FooterRow;


            foreach (GridViewRow row in childgrdview.Rows)
            {

                decimal price;
                Label total = (Label)row.FindControl("lblTotal");
                Label sub = footerRow.FindControl("lblSubTotal") as Label;

                price += decimal.Parse(total.Text);

                sub.Text = price.ToString();
           
            }

        }
                   
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.