Ejemplo n.º 1
0
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.Header &&
           e.Row.RowType != DataControlRowType.Footer &&
           e.Row.RowType != DataControlRowType.Pager)
        {
            short Quantity = 0;
            if (e.Row.RowState != (DataControlRowState.Edit | DataControlRowState.Alternate) &&
               e.Row.RowState != (DataControlRowState.Edit | DataControlRowState.Normal))
            {
                Quantity = Convert.ToInt16(e.Row.Cells[2].Text);
            }
            else
            {
                Quantity = Convert.ToInt16(((TextBox)e.Row.Cells[2].Controls[0]).Text);
            }
            Label labelSum = (Label)e.Row.Cells[5].FindControl("Label1");
            decimal price = Convert.ToDecimal(e.Row.Cells[3].Text);
            decimal sum = (decimal)(price * Quantity);
            labelSum.Text = sum.ToString();
        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label labelFooter = (Label)e.Row.Cells[5].FindControl("Label2");
            mShoppingBag = (ShoppingBag)Session["mShoppingBag"];
            decimal sum = (decimal)mShoppingBag.GetFinalPrice();
            labelFooter.Text = sum.ToString();

        }
    }