添加摘要变量

Adding Summary Variables

我有一个 asp.net 网站,有两种形式。第一个表单包含供用户输入运输信息的输入控件。第二种形式包含摘要信息。我遇到的问题是,当用户通过在第一个表单上按 addButton 添加一个项目时,他们应该能够输入另一个项目,并且这些项目的价格总和应该传递给汇总表,相反,它只是传递单击 addButton 后输入的最新商品的价格。我才刚刚开始 asp.net,如有任何帮助,我们将不胜感激。

protected void addButton_Click(object sender, EventArgs e)
{
    var dollA = new List<decimal>();
    int i = 0;
    for (i = 0; i < 4; i++) { 
        weightInteger = int.Parse(weightTextBox.Text);
        quantityInteger = int.Parse(quanTextBox.Text);
        priceDecimal = decimal.Parse(priceTextBox.Text);

        // Calculate the current item price.
        currentPriceDecimal = priceDecimal * quantityInteger;
        // Format and display the current item price.
        currentTextBox.Text = currentPriceDecimal.ToString("C");

        // Calculate the dollar amount due.
        dollarAmountDecimal += currentPriceDecimal;

        dollA.Add(dollarAmountDecimal);
        dollDec = dollA.Sum();
        Session["Amount"] = dollDec;
    }
}

汇总表:

protected void Page_Load(object sender, EventArgs e)
{
    decimal amount;

    amount = Convert.ToDecimal(Session["Amount"]);

    amountTextBox.Text = amount.ToString("C");
}

根据评论,这似乎适用于 OP。

protected void addButton_Click(object sender, EventArgs e)
{
    if (Session["Amount"] == null)
        Session["Amount"] = Decimal.Zero;

    weightInteger = int.Parse(weightTextBox.Text);
    quantityInteger = int.Parse(quanTextBox.Text);
    priceDecimal = decimal.Parse(priceTextBox.Text);

    // Calculate the current item price.
    currentPriceDecimal = priceDecimal * quantityInteger;
    // Format and display the current item price.
    currentTextBox.Text = currentPriceDecimal.ToString("C");

    // Calculate the dollar amount due.
    dollarAmountDecimal += currentPriceDecimal;

    Session["Amount"] = (decimal)Session["Amount"] + dollarAmountDecimal;
}