Skip to main content
 首页 » 编程设计

c#之在 2 个下拉列表中乘以值

2024年02月20日11pengyingh

我花了 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”隐式转换为“string”

请您参考如下方法:

只需使用:

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

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