从下拉列表中选择第一项时,我的OnSelectedIndexChanged方法未触发。
当选择任何其他索引时,该方法可以正常工作,但是当选择索引0时,我的ddl_OnSelectedIndexChanged永远不会被调用。
标记:
<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged="dll_OnSelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
代码:
protected void dll_OnSelectedIndexChanged(object sender, EventArgs e)
{
if (ddl.SelectedIndex == 0 || ddl.SelectedIndex == 1)
{
// do stuff
}
}
填充ddl:
private void fillDropDownList()
{
List<string> ddlList = new List<string>();
ddlList.Add("");
//filing the rest of the list with strings
ddl.DataSource = ddlList;
ddl.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
fillDropDownList();
}