1

我在 formview 控件上有这个标记。formview 的控件 id 为 scoreGrid:

<asp:Label ID="PercentLabel" runat="server" Text='<%# Eval("PercentCorrect","{0:0.00}%" ) %>'

计算中的所有值都以百分比形式存储在 PercentLabel 控件中,例如 83.33%。

然后在 codebhind 上,在 pageLoad() 事件上,我有这个:

Dim myRow As FormViewRow = scoreGrid.Row
Dim lbscore As Label = DirectCast(myRow.FindControl("PercentLabel"), Label)
If lbscore.Text < "75" Then
    Message.Text = "Your score does not meet minimum requirement"
ElseIf lbscore.Text > "75" Then
    Message.Text = "Congratulations; you have passed the test"
End If

根据用户的分数,显示用户是否通过了测试。

我没有收到任何错误。但是,没有显示任何消息。

我究竟做错了什么?

谢谢

4

1 回答 1

1

当您需要使用数字类型进行此比较时,您正在比较具有大于和小于逻辑的字符串,如下所示:

Dim number As Single 

If Single.TryParse(lbscore.Text, number) Then
    ' Do comparison logic
    If number < 75 Then
        Message.Text = "Your score does not meet minimum requirement"
    ElseIf number >= 75 Then
        Message.Text = "Congratulations; you have passed the test"
    End If
Else
    ' Could not convert text from lbscore to a Single
    Message.Text = "Error trying to determine your score!"
End If    
于 2013-08-13T04:28:35.247 回答