Reputation: 179
I have a Page with 2 repeaters on it and each repeater contains a user control.
The idea is that when you click a button on the usercontrol in the repeater on the left, data is retrieved from the database and set as the datasource for the repeater on the right. I use event bubbling to pass the event from the user control to the page so I can get the data and set it for the other repeater.
My problem is that the ItemDataBound event handler doesn't get called again after setting the repeater source in the event handler of the page for the user control button event.
Here's the layout of the page
<div id="leftDiv">
<asp:Repeater ID="rptUser" runat="server">
<ItemTemplate>
<custom:UserInfo ID="cstUserInfo" runat="server" />
<br />
</ItemTemplate>
</asp:Repeater>
</div>
<div id="rightDiv">
<asp:Repeater ID="rptMessages" runat="server">
<ItemTemplate>
<custom:MessageDetails ID="cstMessageDetails" runat="server" />
</ItemTemplate>
</asp:Repeater>
</div>
And here's the event handler for the user control button click event.
private void cstUserInfo_ShowMessagesClicked(object sender, EventArgs e)
{
UserInfoControl userInfoControl = sender as UserInfoControl;
//Get the messages
messageManager = new MessageManager();
List<Messages> messages = messageManager.GetMessageDetailsByUserId(userInfoControl.CurrentUser.Id).ToList();
rptTimeline.DataSource = messages;
rptTimeline.ItemDataBound += new RepeaterItemEventHandler(rptMessages_ItemDataBound);
rptTimeline.DataBind();
}
When I click the button on the user control the following happens:
Is there any way to bind the new data to the second repeater when a button on the user control in the first repeater is pressed?
Upvotes: 0
Views: 2877
Reputation: 41236
You'll want to use ItemCreated.
repeater.ItemCreated += new ItemCreatedEventHandler()
It's called each time an item is created to be bound to the repeater.
Upvotes: 1