我在同一个 aspx 页面上有两个下拉列表控件
<asp:DropDownList ID="ddlM" runat="server" Width="123px" AutoPostBack="True" OnSelectedIndexChanged="ddlM_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlC" runat="server" Width="123px" AutoPostBack="True" OnSelectedIndexChanged="ddlC_SelectedIndexChanged">
</asp:DropDownList>
两者的 OnSelectedIndexChanged 的 C# 代码如下:
protected void ddlC_SelectedIndexChanged(object sender, EventArgs e)
{
ddlM.SelectedIndex = 0;
ViewState["ddlC"] = true;
ViewState["ddlM"] = false;
BindPGrid();
}
protected void ddlM_SelectedIndexChanged(object sender, EventArgs e)
{
ddlC.SelectedIndex = 0;
ViewState["ddlC"] = false;
ViewState["ddlM"] = true;
BindPGrid();
}
两者都使用一些服务器端代码由数据库记录项填充。现在,“ddlM”的 OnSelectedIndexChanged 事件我想选择“ddlC”的第一个索引,但不触发事件 ddlC_SelectedIndexChanged。对于“ddlC”,与“ddlC”的 OnSelectedIndexChanged 事件相同,我想选择“ddlM”的第一个索引,但不触发事件 ddlM_SelectedIndexChanged。不对,它会触发事件。我该怎么做才能防止它?
谢谢