2010-11-13 46 views
0

我有一個自定義DropDownList控件,SDropDownList。我正在嘗試註冊並激發「SelectedIndexChanged」事件。我明顯是通過向標記添加OnSelectedIndexChanged =「method」屬性開始的,但它不會觸發事件。我也試圖對其進行註冊程序中RepeaterDropDownList事件不在中繼器內觸發

protected void rptrSection1_Bound(object sender, RepeaterItemEventArgs e) 
{ 
    var ctl = e.Item.FindControl("ddlS1") as SDropDownList; 
    ctl.SelectedIndexChanged += new EventHandler(ddlS1_SelectedIndexChanged); 
} 

注意的OnBound事件: 我讀了表明禁用的Repeater ViewState中會解決這個問題的一些不同的論壇帖子。這不適合我。

感謝您的幫助!

按照要求,標記:

<asp:Panel ID="pnlSection1" runat="server"> 
    <asp:Repeater ID="rptrSection1" runat="server" OnItemCommand="rptrSection1_Command" 
     OnItemDataBound="rptrSection1_Bound"> 
     <ItemTemplate> 
       <table class="Section2Table" cellspacing="3"> 
        <tr> 
         <td class="simgv" style="padding: 3px"> 
           <sc:SDropDownList ID="ddlS1" runat="server" OnSelectedIndexChanged="ddlS1_SelectedIndexChanged" > 
            <asp:ListItem Text="Compliant" Value="0" /> 
            <asp:ListItem Text="Other Than Serious" Value="1" /> 
            <asp:ListItem Text="Serious" Value="2" /> 
            <asp:ListItem Text="Critical" Value="3" /> 
           </sc:SDropDownList> 
         </td>        
        </tr> 
       </table> 
      </ItemTemplate> 
    </asp:Repeater> 

+0

您可以發佈控件所在的標記嗎? – Oded 2010-11-13 20:29:30

回答

1

您必須設置的AutoPostBack = true,否則會的SelectedIndexChanged不火,因爲沒有回發到服務器。

+0

哈哈,哇。在我最終進入這個行業之前,這就是我在VS中經常使用Design View的原因。我忘了我總是通過設計人員而不是手動添加該屬性。 – 2010-11-13 20:42:38

相關問題