First make sure your databinding is not resetting your dropdowns.
Here is the code for the control which will nest inside the repeater ItemTemplate
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ListBoxContainer.ascx.cs" Inherits="OAAF.Common.ListBoxContainer" %>
<asp:ListBox ID="lstFromControl" runat="server" Rows="1" DataTextField="Text" DataValueField="Id" OnSelectedIndexChanged="LstFromControl_SelectedIndexChanged" AutoPostBack="true" />
The code behind for the control which will nest inside the repeater ItemTemplate
public partial class ListBoxContainer : System.Web.UI.UserControl
{
//declare the event using EventHandler<T>
public event EventHandler<EventArgs> ListBox_SelectedIndexChanged;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LstFromControl_SelectedIndexChanged(object sender, EventArgs e)
{
//fire event: the check for null sees if the delegate is subscribed to
if (ListBox_SelectedIndexChanged != null)
{
ListBox_SelectedIndexChanged(sender, e);
}
}
}
Note that this above control uses the listbox change event internally, then fires an event of its own: ListBox_SelectedIndexChanged. You could create custom event args here as well, but this uses the standard EventArgs.
Your repeater which has the control may look like this
<asp:Repeater ID="rptTest" runat="server">
<ItemTemplate>
<br />
<ctrl:wucListBox ID="listBoxControl" runat="server" OnListBox_SelectedIndexChanged="ListBoxControl_SelectedIndexChanged" />
</ItemTemplate>
</asp:Repeater>
Register the control at the top of the page the repeater is on, for example
<%@ Register Src="~/Common/ListBoxContainer.ascx" TagName="wucListBox" TagPrefix="ctrl" %>
It handles the event ListBox_SelectedIndexChanged, and the method which handles this is in the code behind of the page the repeater sits on.
protected void ListBoxControl_SelectedIndexChanged(object sender, EventArgs e)
{
//some code
}