Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


pwaddles

113 posts

Master Geek


#16599 18-Oct-2007 13:22
Send private message

Im building an order form for a client, which has three drop down lists which are dependant on the selected data from the previous dropdown list. eg ddl1 determines what is available in ddl2, ddl2 determines what is available in ddl3.

The first two drop down lists are populated using the VS2008 SQLDataSource, which works great, the third I then populate using the SelectedIndex of the second ddl. But the problem I'm having is that when I first load the page, ddl1 and ddl2 have default values loaded into them (the first in the list) but I cant get the SelectedIndex value out of ddl2 for some reason until I select another option in ddl2 thus creating it to postback.

Any thoughts?

Cheers

Create new topic
pwaddles

113 posts

Master Geek


  #91509 18-Oct-2007 13:27
Send private message

Also I have tried ddl2.SelectedIndex = x to give it a default value, but still no luck.



RedJungle
Phil Gale
1108 posts

Uber Geek

Trusted
Red Jungle
Subscriber

  #91524 18-Oct-2007 14:07
Send private message

When you say you can't get the selected index of the dropdownlist, what exactly happens? does it always return -1 or is it actually throwing an exception?

Are you able to post a code snippet?

Cheers

nate
6473 posts

Uber Geek

Retired Mod
Trusted
Lifetime subscriber

  #91607 18-Oct-2007 21:50
Send private message

This is a javascript issue, the onchange event doesn't fire if the selectedindex of the combo box doesn't change.

I'd suggest adding a blank item as the first item in both comboboxes.  If the user selects another item in that combobox, the event you require will fire.  To prevent the user selecting the blank option, do something like:

if not ddlOption1.selectedindex = 0 then ....




RedJungle
Phil Gale
1108 posts

Uber Geek

Trusted
Red Jungle
Subscriber

  #91611 18-Oct-2007 21:58
Send private message

Interesting thought nate, but you should still be able set and retrieve the SelectedIndex / SelectedValue properties of a DropDownList control progmatically without needing to trigger the javascript onChange event (i.e. when AutoPostBack = false). Unless the viewstate isn't enabled?

I suspect this will be just one of this issues where something is slightly amiss in when/where you are setting/getting the values in your code, as I suggested earlier the relevant code being posted should aide greatly.

pwaddles

113 posts

Master Geek


  #91618 18-Oct-2007 22:35
Send private message

Hi again,
thanks for the replys, I'm on my home PC now so cant get source code, but the dropdrows are just standard asp dropdown menus that you click and drag from the left hand side of the screen. They then have their own sqldatasource tpget their data so I dont think I have the option of adding a blank at the top of the list without adding a black to each appropriate entry in the database.

Redjungle, could you please elaborate on viewstate? I'm not familiar with it.

Nate, I tried t 'hardwire' a change to the dropdownlist by waiting for it to load, then in the page_loadcomplete sub routine I set the selected index to be 3. This still didnt work. But I think you're on the right track as it works fine after you choose something.

Cheers

pwaddles

113 posts

Master Geek


  #91693 19-Oct-2007 12:45
Send private message

Hi again, I had a bit more of a look on the web with not much joy :(

Decided just to hard code it all myself and got it working sweet in about an hours worth of coding.

Cheers guys

Hadley

Create new topic





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.