开发者

Raise ItemDataBound Event from Repeater Within User Control to Page

开发者 https://www.devze.com 2022-12-30 19:10 出处:网络
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.

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 tr开发者_运维问答ied this before and if so could I see some code to suggest how it might look.

Many Thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消