2015-07-10 54 views
0

我已創建用戶控件,並在後面的aspx代碼中添加相同的代碼。我想爲aspx頁面中的dropdownlist處理選定的索引更改事件。請幫助我做到這一點。在aspx頁面處理用戶控件下拉列表選擇的索引更改事件

<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 
     } 

回答

1

你還沒有添加上下拉SelectedIndexChanged事件。

在下拉菜單中添加SelectedIndexChanged="ddlparent_SelectedIndexChanged"

<asp:DropDownList ID="ddl_parent" runat="server" CssClass="form-control" AutoPostBack="true" OnSelectedIndexChanged="ddlparent_SelectedIndexChanged"> 
</asp:DropDownList> 
+0

我所添加的第一個下拉選擇指數的變化觸發的事件。其他控制事件未被解僱 –

相關問題