ASP.Net DropDownList selected value

Susan picture Susan · Aug 5, 2011 · Viewed 27.4k times · Source

I have a feeling I'm missing something really obvious, I'm not able to capture the selected value of my DropDownList; the value renaubs the first item on the list. I have set the DropListList autopostback property to true. I have a SelectedIndexChangedEvent which is pasted below. This is NOT on the master page.

protected void ddlRestCity_SelectedIndexChanged(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        r_city = ddlRestCity.SelectedValue.ToString();
    }
}

Here is the DropDownList control:

<asp:DropDownList ID="ddlRestCity" runat="server" 
        Width="100px" AutoPostBack="True" 
        onselectedindexchanged="ddlRestCity_SelectedIndexChanged">
</asp:DropDownList>

Thanx in advance for your help!

Answer

Felan picture Felan · Aug 5, 2011

My off the cuff guess is you are maybe re-populating the list on a post back and that is causing the selected index to get reset.