How do I programmatically set the selectedValue of cascading dropdownlists in C#
Posted on 2008-06-24
I have an ASP.NET 2.0 app that has multiple pages with 2 dropdownlists on.
ddl1 = CostCentre
ddl2 = Employee
Both ddl are bound to sqldatasources and ddl2 has a parameter which is bound to the value of ddl1. This all works fine.
What i want to do is when the user moves from one page to another the dropdownlists are set to the Costcentre and Employee that was selected on the previous page.
The costcentre ddl i have no problem with but its setting the value of the Employee ddl which relies on the costcentre being selected.
Session variable are set with the selected values of the ddl's.
i have tried this code but the employee ddl ends up empty with no value selected.
protected void Page_Load(object sender, EventArgs e)
if (Session["CC"] != null)
ddCCList.SelectedValue = (string)Session["CC"];
if (Session["EmpID"] != null)
ddEmployeeList.SelectedValue = (string)Session["EmpID"];
i have also tried putting similar code in the ondatabound event of the dropdownlists but that doesn't work either.
Any help appreciated.