Solved

vb.net if...then statement help

Posted on 2007-11-26
4
528 Views
Last Modified: 2009-12-16
Ok, I know this is a simple question...so I hope I can get a quick answer.

I'm trying to do a if, then statement that checks for one criteria, and has multiple responses based upon the criteria. The problem is, only ONE response is given, while I want THREE actions to take place. The following is the code;

        If ddlLocation.Text = "Lake Lure, NC" Then
            imgLocation.ImageUrl = "~/halc/images/lakeOff.jpg"
            lblContact.Visible = True
            lblLocPhone.Text = "(877)743-2589"
        ElseIf ddlLocation.Text = "Stanton, KY" Then
            imgLocation.ImageUrl = "~/halc/images/StantonOff.jpg"
            lblContact.Visible = True
            lblLocPhone.Text = "(877)220-0005"
        ElseIf ddlLocation.Text = "Plant City, FL" Then
            imgLocation.ImageUrl = "~/halc/images/PlantOff.jpg"
            lblContact.Visible = True
            lblLocPhone.Text = "(866)757-1771"
        ElseIf ddlLocation.Text = "Fallbrook, CA" Then
            imgLocation.ImageUrl = "~/halc/images/fallbrookOff.jpg"
            lblContact.Visible = True
            lblLocPhone.Text = "(760)728-1064"
        Else
            imgLocation.ImageUrl = "~/halc/images/NoLoc.jpg"
            lblContact.Visible = False
            lblLocPhone.Text = ""
        End If

I am hoping someone can tell me what I'm missing. I know it's simple (and I'll feel stupid once someone answers the question) I just don't know it.
0
Comment
Question by:hacresIT
  • 2
4 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 20350790
Can you elaborate on what you mean by "only ONE response is given, while I want THREE actions to take place"?  If you're referring to having 3 statements inside each branch of the "if" statement, what you have will execute all 3.
0
 
LVL 4

Expert Comment

by:edwardq
ID: 20350813
Use ddlLocation.SelectedItem.Text  instead of ddlLocation.Text.
0
 
LVL 1

Author Comment

by:hacresIT
ID: 20350940
Ok, as it is, when an item is selected, the only thing that currently happens is the image changes as directed by the code;  imgLocation.ImageUrl = "~/halc/images/PlantOff.jpg"

The asp.net lables DO NOT change as directed by the statements given;

 lblContact.Visible = True
 lblLocPhone.Text = "(866)757-1771"


0
 
LVL 4

Accepted Solution

by:
edwardq earned 50 total points
ID: 20351017
Are you setting up the lblContact.Visable = false in the Page_Load? if so you need to check to see if its a this is a page postback.  If so, skip the lblContact and the LocPhone.Text = "".
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now