Dynamic asp:DrownDownList control

B

Bob

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
 
J

Jacques

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
 
D

David C

Have you looked at ASP.Net AJAX? There is a control already built that does
this.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top