尝试获取它,这样如果你左键单击,它将填入4个文本框,然后如果你使用下拉列表并再次点击它,它将填写4个不同的文本框 - 必须让它填写一个共计20个,每次4个。
int carpick, qty, total, i;
protected void Button1_Click1(object sender, EventArgs e)
{
for (i = 0; i != 5; ++i)
{
carpick = 0; qty = 0; total = 0;
{
carpick = Convert.ToInt32(CarpickDD.SelectedItem.Value);
qty = Convert.ToInt32(QTYDD.SelectedItem.Value);
total = ((carpick * qty) + (750 * qty));
Label1.Text = CarpickDD.SelectedItem.Text;
Label2.Text = CarpickDD.SelectedItem.Value;
Label3.Text = QTYDD.SelectedItem.Value;
Label4.Text = Convert.ToString(total);}
if (i != 1)
{
carpick = Convert.ToInt32(CarpickDD.SelectedItem.Value);
qty = Convert.ToInt32(QTYDD.SelectedItem.Value);
total = ((carpick * qty) + (750 * qty));
Label5.Text = CarpickDD.SelectedItem.Text;
Label6.Text = CarpickDD.SelectedItem.Value;
Label7.Text = QTYDD.SelectedItem.Value;
Label8.Text = Convert.ToString(total);
}
}
}
enter code here
答案 0 :(得分:2)
每次点击该按钮,for
循环都会从i = 0
开始。因此,您不会在每次调用到下一次调用时保持任何状态;你的按钮不会“记住”你以前点击它的频率。
也就是说,你也没有在循环中任何使用变量i
(if (i != 1)
除外)。换句话说,你的循环当前在每次点击按钮上都是相同的东西,并且每次点击同样的事情相同的事情。如果你想第二次点击按钮时填写不同的文本框,那么第二次它肯定应该做些不同的事情吗?
答案 1 :(得分:0)
我想你想要这个:
int carpick, qty, total, i = 0;
protected void Button1_Click1(object sender, EventArgs e)
{
carpick = Convert.ToInt32(CarpickDD.SelectedItem.Value);
qty = Convert.ToInt32(QTYDD.SelectedItem.Value);
total = ((carpick * qty) + (750 * qty));
switch (i++)
{
case 0:
Label1.Text = CarpickDD.SelectedItem.Text;
Label2.Text = CarpickDD.SelectedItem.Value;
Label3.Text = QTYDD.SelectedItem.Value;
Label4.Text = Convert.ToString(total);
break;
case 1:
Label5.Text = CarpickDD.SelectedItem.Text;
Label6.Text = CarpickDD.SelectedItem.Value;
Label7.Text = QTYDD.SelectedItem.Value;
Label8.Text = Convert.ToString(total);
break;
case 2:
..... etc ....
}
}