how to get next item in repeater c#, if list is given as datasource?

1.2k Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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);

0
On

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();