Marco Valsecchi

How to identify last item in a nested .Net Repeater

10 marzo 2011 • ⏲️ 1 min.

If you have a typical Orders/Products page and you want to show every product inside every order I think the best solution is to use a Repeater (of products) inside a parent Repeater (of orders).

If you must do something in the last product template of a order how can you reach this condition?

In the OnItemDataBound of a nested Repeater you can count his DataSource casting it to the item collection type; for example:

if (e.Item.ItemIndex == ((List)((Repeater)sender).DataSource).Count - 1)
{
// do something
}


Marco Valsecchi

"Man is still the most extraordinary computer of all" (J.F. Kennedy)