简体   繁体   中英

Why does Repeater.ItemDataBound - Event not trigger anything?

I do register a method for the ItemDataBound - Event like this:

protected void Page_Init(object sender, System.EventArgs e)
{
    MyRepeater.ItemDataBound += MyRepeater_ItemDataBound;
    // ...
}

protected void MyRepeater_ItemDataBound(object sender, 
    System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
    // ...
}

Like this, nothing is triggered, the method is never executed. When I register the method in code-before like

<asp:Repeater ID="MyRepeater" runat="server" 
    OnItemDataBound="MyRepeater_ItemDataBound">

it does work. Why doesn't the former version work?

Thx for any tipps sl3dg3

You might be missing AutoEventWireup=true in Page header in aspx file.

Edit: If buttons handlers do work, perhaps it's problem with databinging - are you sure you are calling DataBind on MyRepeater or any of it's parent control? If you are calling DataBind manually, does it depend on Page.IsPostBack on your page?

Check that AutoEventWireUp is set to true . If AutoEventWireUp is false your Page_Init method will not be executed and so the code that attaches the handler to the ItemDataBound event won't be executed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM