CMSRepeater ItemDataBound fired twice

Vu Hung asked on September 23, 2014 10:57

Hi, I have a webpart that contain a CMSRepeater control:

<cms:CMSRepeater ID="repeater" runat="server" OnItemCommand="repeater_ItemCommand"

In the code behind:

public override void OnContentLoaded()
private void SetupControl()
    var lstToBind = new List<string> {"1"};
    this.repeater.DataSource = lstToBind;
protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        // To Do

The event repeater_ItemDataBound fired 2 times when I debugging.

Is it normal? How to prevent it.


Recent Answers

Brenden Kehren answered on September 23, 2014 13:47

Typically one for the header and one for your first row. You might check to see the other item type that is binding in that event.

0 votesVote for this answer Mark as a Correct answer

Vu Hung answered on September 24, 2014 04:33

Yes, I checked the item type that is binding in the event, you can see the condition if in my code.

You can create a sample webpart and copy the code example above then you will see the repeater_ItemDataBound fired 2 times insteads of run through the item of repeater.

Pleae notice that it not happen if you bind the datasource at page_load event. It happen only when we bind the datasource at OnContentLoaded event.

I'm using KenticoCMS7. Thanks

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.