1

我有 2 天最好的部分试图弄清楚如何相互“乘以 2 个下拉列表”并将其显示在标签中......

就像在数学中一样,当你把 2 个数字相乘时..

请帮助我...

欢迎所有建议

Protected void Button1_Click(object sender, EventArgs e)
{
     int amount1 = int.parse(DropDownList1.selectedValue.ToString());
     int amount2 = int.parse(DropDownList1.selectedValue.ToString());

     Label.Text = amount1 * amount2;
}

我收到一个错误:

无法将类型“Int”隐式转换为“字符串”

4

2 回答 2

4

只需使用:

Label.Text = (amount1 * amount2).ToString();

因为您不能将整数结果分配给字符串 Label.Text 属性。

于 2012-11-07T23:18:38.293 回答
0

你也可以这样做

int val = amount1 * amount2;
Label.Text = val.ToString();

Label.Text期望 String 并且您试图将整数分配给它。

于 2012-11-07T23:51:43.780 回答