单选按钮列表selectedItem.Value与字符串相比不起作用

时间:2010-12-12 08:35:43

标签: asp.net vb.net radiobuttonlist

我正在使用VB.NET而且我无法将单选按钮列表selectedItem.Value与字符串进行比较,它不起作用......这里是代码:(我也尝试过selectValue它不起作用

Response.Write("RB1: " + rblOne.SelectedItem.Value + " FML FML FML<br/>")
            If rblOne.SelectedItem.Value = "No" Then
                Response.Write("Hey there!<BR/>")
                pnlR1.Visible = True
                If NumberOfAnswers = 7 Then
                    Score = Score - 10
                ElseIf NumberOfAnswers = 6 Then
                    Score = Score - 15
                Else
                    Score = Score - 20
                End If
                Response.Write("Score: " + Score.ToString)
            End If
    Response.End()

如果rblOne.SelectedItem.Value =“No”然后不工作,请注意那里的调试语句,这里是输出:

alt text

为什么不评估rblOne.SelectedItem.Value =“No”!?!?!?我尝试了rblOne.SelectedValue,这不起作用,我添加了.ToString两个,这没有帮助,我甚至尝试了它与“没有”.ToString ...这没有任何意义。

1 个答案:

答案 0 :(得分:1)

    If rblOne.SelectedIndex > -1 AndAlso rblOne.Items(rblOne.SelectedIndex).Value.ToString = "No" Then
        'Code to run if the selected list item in the radio button list has a value of "No"
    End If