Monday, March 26, 2012
Populate A Dropdown From Another Dropdown
(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?
Saturday, March 24, 2012
populate dropdown onchange without reloading page
When the county changes, I want the district dropdown to automatically
update with a list of districts in that county, but I don't want the
page to have to reload when county changes.
I remember doing this before in classic ASP with javascript, can I do
this with a dropdownlist in ASP.NET or should I stick with the HTML
dropdown?
Thanks,
Peter
--
"I hear ma train a comin'
... hear freedom comin"It has to be done in JavaScript. Whether you use an ASP.Net dropdownlist or
the HTML <select> really doesn't matter. Just note that items added to the
dropdownlist dynamically won't exist when you do post back. You'll need to
use the good-old Request.Form.
You can check out:
http://msdn.microsoft.com/library/d...tSpicedAjax.asp
which has an AJAX implementation of creating linked dropdowns..
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Stimp" <ren@.spumco.com> wrote in message
news:slrndkl22h.k78.ren@.carbon.redbrick.dcu.ie...
>I have 2 dropdowns, county and district.
> When the county changes, I want the district dropdown to automatically
> update with a list of districts in that county, but I don't want the
> page to have to reload when county changes.
> I remember doing this before in classic ASP with javascript, can I do
> this with a dropdownlist in ASP.NET or should I stick with the HTML
> dropdown?
> Thanks,
> Peter
> --
> "I hear ma train a comin'
> ... hear freedom comin"
populate dropdown onchange without reloading page
When the county changes, I want the district dropdown to automatically
update with a list of districts in that county, but I don't want the
page to have to reload when county changes.
I remember doing this before in classic ASP with javascript, can I do
this with a dropdownlist in ASP.NET or should I stick with the HTML
dropdown?
Thanks,
Peter
--
"I hear ma train a comin'
... hear freedom comin"It has to be done in JavaScript. Whether you use an ASP.Net dropdownlist or
the HTML <select> really doesn't matter. Just note that items added to the
dropdownlist dynamically won't exist when you do post back. You'll need to
use the good-old Request.Form.
You can check out:
http://msdn.microsoft.com/library/d...tSpicedAjax.asp
which has an AJAX implementation of creating linked dropdowns..
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Stimp" <ren@.spumco.com> wrote in message
news:slrndkl22h.k78.ren@.carbon.redbrick.dcu.ie...
>I have 2 dropdowns, county and district.
> When the county changes, I want the district dropdown to automatically
> update with a list of districts in that county, but I don't want the
> page to have to reload when county changes.
> I remember doing this before in classic ASP with javascript, can I do
> this with a dropdownlist in ASP.NET or should I stick with the HTML
> dropdown?
> Thanks,
> Peter
> --
> "I hear ma train a comin'
> ... hear freedom comin"