如何选中复选框,然后单击“提交”,如何将总计添加到标签?

时间:2013-02-05 20:33:22

标签: asp.net

我有两个预先填充radiobutton的复选框。当我在复选框上选择“是”时,它会打开单选按钮,该按钮被选中为真,文本为数字。我想知道如何选择一个复选框并在我单击提交按钮时将其显示为总计,并且如果我选中并选中两个复选框,它必须将两个复选框加上radiobutton,它在标签结尾显示我的单个复选框编号按钮编号和显示为总计,因此如果选中单个复选框,则显示单个总页数(如果同时选中两个复选框)将两个数字相加,并在单击提交时在标签中显示总计。任何帮助都会做,非常感谢谢谢

继承我的代码:

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

    Dim number1 As Double
    Dim number2 As Double
    Dim answer As Double
    Dim total As Integer

    number1 = Double.Parse(RadioButton1.Text)
    number2 = Double.Parse(RadioButton2.Text)

    If CheckBox1.Checked = True Then
        answer = number1
        answerLbl.Text = answer.ToString()
    ElseIf CheckBox2.Checked = True Then
        answer = number2
        answerLbl.Text = answer.ToString()
    ElseIf CheckBox1.Checked = True And CheckBox2.Checked = True Then
        answerLbl.Text = total.ToString()
    End If

End Sub

1 个答案:

答案 0 :(得分:1)

我希望这就是你的期待。

    If CheckBox1.Checked = True And CheckBox2.Checked = True Then   
    answerLbl.Text =( Double.Parse(RadioButton1.Text)+ Double.Parse(RadioButton2.Text)).ToString()

    ElseIf CheckBox2.Checked = True Then
    answerLbl.Text =RadioButton2.Text
    ElseIf CheckBox1.Checked = True Then
    answerLbl.Text = RadioButton1.Text
  End If

 End Sub