PDA

View Full Version : Selected Value of DDL on Page Load


xbabigyrlx
08-30-2006, 08:44 PM
I am using a databound drop down list and want to set the first item in the list to be selected. I have tried ddlSelectLocation.SelectedIndex = 0; this is selected the first item in my list but I am unable to retrieve the value.

I am using the following code in my SelectedIndexChanged event:

Session["Loc"] = ddlSelectLocation.SelectedItem.Value.ToString();
Label1.Text = Session["Loc"].ToString();

this is working fine.... how do I get to this for the first item in my list on page load....

Any help is appreciated... Thanks in advance

CurtWRC
08-31-2006, 01:49 AM
Correct me if Im wrong, but I thought by default the first item on the list is always selected unless stated otherwise anyway.

xbabigyrlx
08-31-2006, 01:19 PM
When I try to find the selected value on page load and save it to a session I get an error - referance not set to an instance of an object. Even if I specifically declare ddlSelectLocation.SelectedIndex = 0;