Question

I want to change a DropDownList depending on the selected index of another DropDownList, so that if I change a value in the first dropdownlist, the second dropdownlist should change too.

Im using the SelectedIndexChanged Event but right now, if I change the first dropdownlist the second dropdownlist doesn't change.

I set a breakpoint on the SelectedIndexChange Event, but after running the code and changing the index of the DropDownList, the debugger never stopped at the breakpoint. Only after reloading or clicking on a button, the debugger will jump into the function. How I can do this in asp.net :(

Here is the EventHandler for the first dropdownlist:

protected void drpCompanyLocation_SelectedIndexChanged(object sender, EventArgs e)
        {
            drpCompanyDepartment.DataSource = (object)ActiveDirectoryManager.GetDepartmentsByLocation(domaincontroller, drpCompanyLocation.SelectedValue); 
            drpCompanyDepartment.DataBind();
        }
Was it helpful?

Solution

I think you don't have AutoPostBack=true added to the DropDownList in your aspx file. If you add this attribute, changing the selected index will automatically cause your event to fire. For more information see: http://asp-net-example.blogspot.nl/2009/03/how-to-use-dropdownlist-autopostback.html

OTHER TIPS

Make sure Autopostback is set to true(in dropdown properties) and set OnSelectedIndexChanged attribute to point function where you can use drpCompanyLocation.SelectedValue to access first dropdown value.

if this doesn't work you have to show your code here.

You can also use cascading dropdowns if you dont want a post back

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/CascadingDropDown/CascadingDropDown.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top