If it has value then try with this way.
ddCCList.Items.FindByText(
Main Topics
Browse All TopicsI 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"];
ddEmployeeList.DataBind();
if (Session["EmpID"] != null)
{
ddEmployeeList.SelectedVal
}
}
}
i have also tried putting similar code in the ondatabound event of the dropdownlists but that doesn't work either.
Any help appreciated.
Anthony
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi vdramu,
I still get the "Object reference not set to an instance of an object." but i have found a way to do it.
Putting the code in the databound event of the dropdownlist works fine. I tried this before but i had ddEmployeeList.DataBind();
Here is the code.
protected void ddCCList_DataBound(object sender, EventArgs e)
{
if (Session["CC"] != null)
{
ddCCList.SelectedValue = (string)Session["CC"];
}
}
protected void ddEmployeeList_DataBound(o
{
if (Session["EmpID"] != null)
{
ddEmployeeList.SelectedVal
}
}
Thanks for trying to help with this.
Anthony
Business Accounts
Answer for Membership
by: ydramuPosted on 2008-06-24 at 07:14:14ID: 21855937
Could you verify once your Session["CC"] value is not null.