views:

20

answers:

1

I have a repeater that has an OnItemDataBound event on it. For some reason the repeater has three items being bound to it. But then I try the below it only writes '2' at the top of the page. The repeater itself does show the three items but this loop in the ondatabound event doesnt see the last item. Why?

protected void colourRepeater_ItemBound(object sender, RepeaterItemEventArgs e)
{
    int count = 0;
    foreach (RepeaterItem item in rptAssoicatedProducts.Items)
    {
        count++;
    }
    Response.Write(count.ToString());
}
+1  A: 

Try this instead :

int count = 0;
protected void colourRepeater_ItemBound(object sender, RepeaterItemEventArgs e)
{
    count++;
    Response.Write("Items so far : " + count.ToString());
}

EDIT: When the ItemDataBound event is triggered, the RepeaterItem is not linked to the Repeater yet ... only the related data is.

tsimbalar
yes that does work but im then wanting to access controls in the item i.e Literal litSomeStuff = ((Literal)e.Item.FindControl("litSomeStuff "));
phil crowe
never mind worked it out! http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.onitemdatabound.aspx
phil crowe