I have an ASP DropDown, declared like this:
<asp:DropDownList ID="DropDown1"
runat="server"
OnSelectedIndexChanged="DropDown1_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
The data is filled in this way:
DropDown1.DataSource = source;
DropDown1.DataTextField = "Key";
DropDown1.DataValueField = "Value";
DdlCat1.DataBind();
“source” is a dictionary:
Dictionary<int, string> source = new Dictionary<int, string>();
The selectedIndexChanged method looks like this:
public void DropDown1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList temp = (DropDownList)sender;
Console.WriteLine(temp.SelectedValue);
}
Now lets say I have item1, item2 and item3 in my dropdown. At the moment i have selected item1. Now the problem is, if i click in item2, the SelectIndexChanged Method is fired BUT the SelectedValue always stays at “item1”. So, what am I doing wrong?
Where is your data filled? If your data is filled on page load or something then due to the page life cycle you’ll overwrite your data source every time