台灣最大程式設計社群網站
線上人數
630
 
會員總數:244893
討論主題:188887
歡迎您免費加入會員
討論區列表 >> C# >> checkBox 商品總金額計算???
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
checkBox 商品總金額計算???
價值 : 50 QP  點閱數:3454 回應數:5

樓主

ryan
門外漢
0 1
24 3
發送站內信

小弟用的是 visual c#2008,
請問~我用checkBox的選擇方式,
要加總商品的金額要如show?
我只show出個別商品的金額,還要求一個 總金額結果~
我知道是用sum ,但是都try失敗,請指點一下

程式碼如下

private void button1_Click(object sender, EventArgs e)

{
string like = "你選的商品是:";

if (checkBox1.Checked) like += "拖鞋," + "50元,";

if (checkBox2.Checked) like += "眼鏡," + "300元,";

if (checkBox3.Checked) like += "棒球帽," + "250元,";

richTextBox1.Text = (like);


}

本篇文章發表於2010-01-11 14:07
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
最有價值解答

達可達
檢舉此回應

本篇文章回覆於2010-01-11 17:07
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
作者回應

ryan
檢舉此回應
謝謝 達可達 的回覆^^ ,你的回答很好,
但我現在還需要 加總兩個 checkBox的總金額要怎麼做?
是用 for 迴圈嗎?因為建置都失敗了,拜託一下了~

比如這樣
private void button1_Click(object sender, EventArgs e)
{
string strTxt = "你選的商品是:";
int count = 0;

if (checkBox1.Checked)
{
strTxt += "拖鞋," + "50元,";
count += 50;
}

if (checkBox2.Checked)
{
strTxt += "眼鏡," + "300元,";
count += 300;
}

strTxt += Environment.NewLine + "總金額:" + count.ToString() + "元";

richTextBox1.Text = strTxt;

}

//第二個
private void button2_Click1(object sender, EventArgs e)
{
string strTxtb = "你選的商品是:";
int count1 = 0;

if (checkBox3.Checked)
{
strTxtb += "口罩," + "25元,";
count1 += 25;
}

if (checkBox4.Checked)
{
strTxtb += "手套," + "80元,";
count1 += 80;
}

strTxtb += Environment.NewLine + "總金額:" + count.ToString() + "元";

richTextBox1.Text = strTxtb;

}
// 第三個button按下要加總前面checkBox的金額

private void button3_Click(object sender, EventArgs e)
{
richTextBox3.Text = ;
}
本篇文章回覆於2010-01-12 11:05
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
3樓
回應

小歐ou
捐贈 VP 給 小歐ou 檢舉此回應

本篇文章回覆於2010-01-12 13:51
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
4樓
回應

以利亞
檢舉此回應
您好 我依照您的方式計算checkbox中的數值,但是上面的內容卻消失了,只有在價錢計算之後內容有顯示,不知道哪邊有錯誤?
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Label5.Text = "考生" + TextBox1.Text;
if (RadioButton1.Checked)
Label5.Text += "先生" + "<br />";
else
Label5.Text += "女士" + "<br />";

string strTxt = "選考:";
int count = 0;
if (CheckBox1.Checked)
{
strTxt += "Word ";
count += 150;
}
if (CheckBox2.Checked)
{
strTxt += "PPTX ";
count += 150;
}
if (CheckBox3.Checked)
{
strTxt += "Excel ";
count += 200;
}
if (CheckBox4.Checked)
{
strTxt += "Access ";
count += 250;
}

strTxt += Environment.NewLine + "合計:" + count.ToString() + "元"+"<br/>";
Label5.Text = strTxt;

if (RadioButton3.Checked)
Label5.Text +="以"+ "現金" +"付款"+ "<br />";
else
Label5.Text += "以" + "信用卡" + "付款" + "<br />";
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server" Text="考生:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Height="19px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="性別:"></asp:Label>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
Text="男" GroupName="a" Checked="True" />
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
Text="女" GroupName="a" />
<br />
<asp:Label ID="Label3" runat="server" Text="選考科目:"></asp:Label>
<br />
<asp:CheckBox ID="CheckBox1" runat="server" Text="Word" />
<br />
<asp:CheckBox ID="CheckBox2" runat="server" Text="PPTX" />
<br />
<asp:CheckBox ID="CheckBox3" runat="server" Text="Excel" />
<br />
<asp:CheckBox ID="CheckBox4" runat="server" Text="Access" />



<br />
<asp:Label ID="Label4" runat="server" Text="付款方式:"></asp:Label>
<asp:RadioButton ID="RadioButton3" runat="server" Text="現金" GroupName="b"
Checked="True" />
<asp:RadioButton ID="RadioButton4" runat="server" Text="信用卡" GroupName="b" />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="確定" />
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>

</div>
</form>
</body>
</html>
本篇文章回覆於2013-04-27 15:06
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
5樓
回應

王俊邦
檢舉此回應
if (checkBox1.Checked) 的Checked哪來的?
本篇文章回覆於2019-08-18 09:11
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.