Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a Repeater control which in some of its cells contains a UserControl which contains a DropDownList. On the ItemDataBound event of the Repeater control I'm assigning an event to the DropDownList like so:

protected void MyRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)  
{  
...  
MyControl myControl = (MyControl)e.Item.FindControl("MyControl01");  
myControl.DataSource = myObject;  
myControl.DataBind();  
myControl.DropDownList.SelectedItemChange += MyMethod_SelectedIndexChanged;  
myControl.DropDownList.AutoPostBack = true;  
....  
}  

protected void MyMethod_SelectedIndexChanged(object sender, EventArgs e)  
{  
//Do something.  
}

The event never fires. Please I need help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
257 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your event is not being raised in a PostBack because your event handler has not been attached (it is only attached during the iteration of the page life-cycle when your repeater is databound).

If you attach your event handler declaratively in the markup such as:

<asp:Repeater ID="Repeater1" runat="server">
     <ItemTemplate>
         <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" />
    </ItemTemplate>
</asp:Repeater>

Then your event handler will be called during PostBacks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...