当SelectedItemEvent被触发时,SelectedItem不会改变.净下拉)
本文关键字:改变 SelectedItem SelectedItemEvent | 更新日期: 2023-09-27 18:17:06
我有一个ASP下拉菜单,声明如下:
<asp:DropDownList ID="DropDown1"
runat="server"
OnSelectedIndexChanged="DropDown1_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
数据按如下方式填写:
DropDown1.DataSource = source;
DropDown1.DataTextField = "Key";
DropDown1.DataValueField = "Value";
DdlCat1.DataBind();
"source"是字典:
Dictionary<int, string> source = new Dictionary<int, string>();
selectedIndexChanged方法如下所示:
public void DropDown1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList temp = (DropDownList)sender;
Console.WriteLine(temp.SelectedValue);
}
现在假设在下拉菜单中有item1, item2和item3。目前我选择了item1。现在的问题是,如果我点击item2, SelectIndexChanged方法被触发,但SelectedValue总是停留在"item1"。那么,我做错了什么?
您的数据填充在哪里?如果数据是在页面加载时填充的那么根据页面生命周期每次