DropDownList event not firing within Repeater
I have a custom DropDownList control, SDropDownList. I am trying to register and fire the 'SelectedIndexChanged' event. I obviously started by adding the OnSelectedIndexChanged="method" attribute to the markup but it would not fire the event. I also tried registering it programmatically in the OnBound event of the Repeater
protected void rptrSection1_Bound(object sender, RepeaterItemEventArgs e)
{
var ctl = e.Item.FindControl("ddlS1") as SDropDownList;
ctl.SelectedIndexChanged += new EventHandler(ddlS1_SelectedIndexChanged);
}
Note: I had read some different forum posts that indicated disabling the ViewState of the Repeater would solve this problem. This is not an option for me.
Thanks for the help!
As requested, the markup:
<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>
You must set AutoPostBack=true, otherwise SelectedIndexChanged will not fire, because there is no postback to a server.
精彩评论