Monday, March 26, 2012

Populate A Dropdown From Another Dropdown

I have a page that has two dropdowns on it. When the page loads, the first box is populated from an Access table. Here's the tricky part for me...

(Just when I think I understand how "postback" works, I find I'm wrong again!)

I have the dropdown set to autopostback=true. When the user selects a choice in this dropdown, the page postsback (I think) and I want it to then query another table in the same database to fill the second dropdown list AND keep the original dropdown list's selection.

For some reason, I can get it to fill the original dropdown, but then when it postsback, I get an error because my SQL statement to load the second dropdown looks like this:

Dim objSeriesDA As New OleDb.OleDbDataAdapter("SELECT * FROM Series WHERE fldProviderID=" & lstProvider.SelectedItem.Value & " ORDER BY fldSeriesNumber DESC", objSeriesCN)

Apparently, when the page postsback, the original dropdown list loses its selection, causing the SQL statement above to error out on a null reference.

Any ideas?

If need be, I can throw this up on a server so you all can see what I'm talking about... I can post the full source as well.

Thanks!

HWKY
:)wrap the code that is filling your first drop down list with this:

If Not Page.IsPostBack Then
'...your code here.
End If
Does anyone have a link to some information that explains PostBack in depth?
well, this link (http://www.15seconds.com/Issue/020102.htm) helped me with some basics on the page lifecycle when i was having user control postback problems. Really, there's not much more to the kind of postback stuff in your first post. If you know how the page loads and when control events are evaluated, that's pretty much it. Were you looking for information on how to roll your own PostBack handler or something else?

0 comments:

Post a Comment