Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Dynamic asp:DrownDownList control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob - 06 Dec 2007 23:02 GMT
I have a static AutoPostBack asp:DrownDownList and depending on the selected
content of this list, I want to either 1) not do anything or 2) generate and
populate a new asp:DrownDownList below it.  How do I do this on the server
side?  I am trying to do this with minimal client-side JavaScript being
generated.

Thanks
Jacques - 07 Dec 2007 06:53 GMT
If I'm understanding you correctly, we're talking about the following
hypothetical scenario: You have a country list and when the user makes a
selection you either do nothing or you load a list of States/Regions
depending on the selection made?

If that scenario is near enough, you could consider the following approach:
At design time, create the second dropdownlist where ever it should be and
set it's visibility to false, or if you don't mind the user seeing it, set
it's enabled property to false.

Capture the Country list's SelectedIndexChanged event and based on your
conditions either load the second list or do nothing.

eg.
protected void Countries_SelectedIndexChanged(....,....)
{
     if (Countries.SelectedIndex > 0)
     {
            Regions.DataSource =
BizLayer.GetRegions(Convert.ToInt16(Countires.SelectedValue));
            Regions.DataTextField = "textField";
            Regions.DataValueField = "valueField";
            Regions.DataBind();
     }
}

Make sure your viewstate is enabled for these lists else you may not get the
expected result.

Hope this helped.
Cheers
Jacques

> I have a static AutoPostBack asp:DrownDownList and depending on the selected
> content of this list, I want to either 1) not do anything or 2) generate and
[quoted text clipped - 3 lines]
>
> Thanks
Bob - 07 Dec 2007 07:44 GMT
Thanks for your response.  However on the internet I found exactly what I
was looking for in the following article:

http://aspnet.4guysfromrolla.com/articles/081402-1.aspx

Thanks again.
David C - 07 Dec 2007 17:01 GMT
Have you looked at ASP.Net AJAX?  There is a control already built that does
this.

David
> Thanks for your response.  However on the internet I found exactly what I
> was looking for in the following article:
>
> http://aspnet.4guysfromrolla.com/articles/081402-1.aspx
>
> Thanks again.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.