Search code examples
asp.netvb.netformview

No messages from my code is getting displayed. Am I doing this incorrectly?


I have this markup on formview control. The formview has a control id of scoreGrid:

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

All the values from calculations are stored in PercentLabel control as percentages like 83.33% as an example.

Then On codebhind, on pageLoad() event, I have this:

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

Based on user's scores, show that the user either passed the test or not.

I am not getting any errors. However, no message is getting displayed.

What am I doing wrong?

Thank you


Solution

  • You are comparing strings with greater than and less than logic when you need to use numeric types to do this comparison, like this:

    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