1

How to get next item in repeater by index or any other way?

e.g. in Sitecore if I'm getting the current item in repeater as

Item currentItem = (Item)e.Item.DataItem;

How can I get item which is next in the list which is given as the datasource?

Pratik Wasnik
  • 191
  • 1
  • 17
  • possible duplicate of [How to get the next and previous row value in repeater item command?](http://stackoverflow.com/questions/16858684/how-to-get-the-next-and-previous-row-value-in-repeater-item-command) – Kasaku Dec 02 '14 at 18:04

2 Answers2

1

Thanks Thomas ,

I got one similar approach . Declared list global and in repeater databound used :

Item currentItem = (Item)e.Item.DataItem;

int index = myList.IndexOf(currentItem);
Item nextItem = myList.ElementAt(index + 1);

Pratik Wasnik
  • 191
  • 1
  • 17
0

You should make the Item List available to the method where you need it. Then you could do something like this:

 Item currentItem = (Item)e.Item.DataItem;
 Item nextItem = MyList
                 .SkipWhile(item => item.ID != currentItem.ID)
                 .Skip(1)
                 .FirstOrDefault();