我有一个有两种形式的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");
}
答案 0 :(得分:0)
根据评论,这似乎适用于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;
}