user1055487
user1055487

Reputation: 261

asp.net vb.net why is this IF not working?

I used to have this working as so....

 Dim AnnEnt As Label = FormView1.FindControl("Holiday_RemainingLabel")

    txtNoofDays.Text.ToString()
    AnnEnt.Text.ToString()

    If txtNoofDays.Text >= AnnEnt.Text Then

        lblHolRequestResponse.Text = "Your holiday could not be saved"
    Else

I've recently change it to this and it no longer works

    Dim remain As TextBox = FormView1.FindControl("Holiday_RemainingTextBox")



    txtNoofDays.Text.ToString()
    remain.Text.ToString()

    If txtNoofDays.Text >= remain.Text Then

        lblHolRequestResponse.Text = "Your holiday could not be saved"

    Else

What is the difference between the textbox in the formview and label in the formview to keep this from working?

i've since tried...

  Dim days = txtNoofDays.Text

    days.ToString()
    AnnEnt.Text.ToString()
    remain.Text.ToString()
    If remain.Text.ToString < days.ToString Then
        lblHolRequestResponse.Text = "Your holiday could not be saved"

Upvotes: 1

Views: 214

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460360

If you want to compare strings numerical, cast them to numbers.

For example(asssuming they are ints):

Dim remain As TextBox = FormView1.FindControl("Holiday_RemainingTextBox")
Dim remaining = Int32.Parse(remain.Text)
Dim numOfDays = Int32.Parse(txtNoofDays.Text)

If numOfDays  >= remaining  Then
    lblHolRequestResponse.Text = "Your holiday could not be saved"
End If

Int32.Parse Method

Otherwise you're comparing alphabetically.

String.CompareTo Method

Upvotes: 3

Related Questions