views:

82

answers:

1

I have a user control that contains a repeater. We have added some paging and sorting into the user control and it all works well.

What I need now is a nice way to catch the OnItemDataBound event of the inner repeater and then bubble it up to be accessible directly from the user control from within the page.

We have tried catching it and then declaring it in the user control but it just won't work. Has anyone ever tried this before and if so could I see some code to suggest how it might look.

Many Thanks

A: 

Try something like this:

<asp:Repeater ID="Repeater1" runat="server" 
    onitemdatabound="Repeater1_ItemDataBound">
  </asp:Repeater>

Then subscribe to the event, and publish another event with the same data

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  OnInnerRepeaterItemDataBound(sender,e);
}

public event EventHandler<RepeaterItemEventArgs> InnerRepeaterItemDataBound;
public void OnInnerRepeaterItemDataBound(object sender, RepeaterItemEventArgs e)
{
  if (InnerRepeaterItemDataBound != null)
    InnerRepeaterItemDataBound(sender, e);
}

That should do it, now you can subscribe to the user control Event InnerRepeaterItemDataBound that would be fired when your inner Repeater1_ItemDataBound fire.

alejandrobog