我已创建用户控件并在aspx代码中添加相同的内容。我想在aspx页面中为dropdownlist处理选定的索引更改事件。请帮助我这样做。
<div class="row">
<div class="col-lg-2">
<asp:Label ID="lbl_parent" runat="server" Text="Parent Node" CssClass="control-label"></asp:Label>
</div>
<div class="col-lg-6">
<asp:DropDownList ID="ddl_parent" runat="server" CssClass="form-control" AutoPostBack="true">
</asp:DropDownList>
</div>
</div>
phContactDetails.Controls.Add(LoadControl("~/UserControl/WUC_DisLabelControl.ascx"));
foreach (var control in phContactDetails.Controls)
{
var usercontrol = control as WUC_DisLabelControl;
DropDownList ddl_parenrt = ((DropDownList)usercontrol.FindControl("ddl_parent"));
ddl_parenrt.SelectedIndexChanged += new EventHandler(ddlparent_SelectedIndexChanged);
}
protected void ddlparent_SelectedIndexChanged(object sender, EventArgs e)
{
throw new NotImplementedException(); //Not Firing
}
答案 0 :(得分:1)
您尚未在下拉列表中添加SelectedIndexChanged
个事件。
在下拉列表中添加SelectedIndexChanged="ddlparent_SelectedIndexChanged"
。
<asp:DropDownList ID="ddl_parent" runat="server" CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="ddlparent_SelectedIndexChanged">
</asp:DropDownList>