c# - 选中 CheckBox 时如何添加整数值?

标签 c# asp.net

我希望在选中复选框时将值添加到整数 (int priceTotal)。该练习用于在网络表单中订购披萨。我希望能够根据选择的尺寸和浇头添加到总价中。

int priceTotal = 0;

if (smallPizzaCheck.Checked) 
{
    priceTotal + 10;
}
else if (mediumPizzaCheck.Checked) 
{
    priceTotal + 13;
}

//Et cetera, et cetera

orderTotal.Text = Convert.ToString(priceTotal);

最佳答案

int priceTotal = 0;

  if (smallPizzaCheck.Checked) 
 {
  priceTotal = priceTotal + 10;
 }

 else if (mediumPizzaCheck.Checked) 
 {
 priceTotal = priceTotal + 13;
 }

 //Et cetera, et cetera

 orderTotal.Text = Convert.ToString(priceTotal);

Just try this....whenever check box checked...the price total added..again and again... so you can sum into (priceTotal value) and display into textbox name("orderTotal.Text")

关于c# - 选中 CheckBox 时如何添加整数值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58003896/

相关文章:

c# - RichTextBox 不处理换行符/回车符

c# - 将 DataTable 绑定(bind)到 DetailsView 控件

c# - 带文件依赖项的 ASP.NET 缓存 : static var vs. AspNet 缓存与 memcached

c# - 将 HTML 表格转换为图像文件

asp.net - 重新格式化所见即所得生成的 html 文件

c# - 将递归转换为迭代

c# - System.Threading.Timer 与 System.Threading.Thread.Sleep 解析 - .NET Timer 不使用系统时钟解析

c# - Windows 和 Linux 应用程序之间的管道

ASP.NET 数据注释 : How to validate a List of string?

c# - 在委托(delegate)中获取委托(delegate)参数