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




--------------------------------
Core 2 Duo e6850 3Ghz
4 X 1Gb DDR2 @ 800Mhz
GeForce 8800 GT 512Mb
P35 DS3L Mobo

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.




--------------------------------
Core 2 Duo e6850 3Ghz
4 X 1Gb DDR2 @ 800Mhz
GeForce 8800 GT 512Mb
P35 DS3L Mobo



RedJungle
Phil Gale
1108 posts

Uber Geek
+1 received by user: 46

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
+1 received by user: 458

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
+1 received by user: 46

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




--------------------------------
Core 2 Duo e6850 3Ghz
4 X 1Gb DDR2 @ 800Mhz
GeForce 8800 GT 512Mb
P35 DS3L Mobo

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




--------------------------------
Core 2 Duo e6850 3Ghz
4 X 1Gb DDR2 @ 800Mhz
GeForce 8800 GT 512Mb
P35 DS3L Mobo

Create new topic








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.