Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Check variable before applying?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Check variable before applying?

 Post Reply Post Reply
Author
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Topic: Check variable before applying?
    Posted: 12 June 2006 at 3:32am
I have a variable which is applied to a dropdownlist, to set which item in the dropdownlist is by default selected. The problem is, that based upon another dropdownlist the items available in the second dropdownlist are determined. Therefore, while ID 10 might be valid if one selects option one from the first dropdownlist, it might not be if option two. For example, if one selects Pennsylvania ID 5 (linked to bucks county) may be valid, but if they select New York ID 5 is not going to be valid b/c NY does not have a Bucks County.
Now the problem is that it is conceivable that the variable will contain an ID which is not in the dropdownlist, so i need to check the variable before I apply it. In pseudo code something like this:
If varA is in DropDownList.Values Then
DropDownList.SelectedValue = varA
End If
That way I don't crash every time the variable isn't what it should be. Any thoughts?
David.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 12 June 2006 at 2:17pm
Why don't you just fill the counties listbox when the state listbox selectedvalue has been changed.

You can also use Atlas (atlas.asp.net) to do this beautifully without a postback.
Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 14 June 2006 at 4:29am
I actually already have that implemented. When the state is selected it postsback and selects the counties in that state. Here is an example of how the problem arises:
Jane visits BetterNeighbours. She currently lives in Albany County New York. She sets Albany County as her favorite county. She is moving to Bucks County Pennsylvania. She has moved some stuff to Bucks and then realizes she doesn't need it, so she decides to list it on better neighbours. She clicks on Pennsylvania for the state and Better Neighbours creates a list of counties in a dropdownlist that are in PA. Then Better Neighbours attempts to set the focus of the DropDownList to the favorite county, but because the favorite county is in New York it isn't party of the dropdownlist and the program crashes.
   I think I have figured out a way to do it however. I can say:
If SelectedCounty.State != SelectedStateID Then
   DropDownList1.Default
Else
   DropDownList1.SelectedValue = SelectedCounty.State
(pseudo-code)
David.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.