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

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?

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

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

Related

How to "remove all duplicates and original of duplicate" from a list of objects in Java 8?

I got two:
registryId:1
registryID:1
registryID:2
The final list should be: I mean remove 1 compeletly
registryID:2
I got this solution:
List<TerpAccountListV> terpAccountListVFinal = compareUpdate(terpAccountListV, xxedgeAccountsListV);
Set<TerpAccountListV> set = terpAccountListVFinal.stream()
.collect(Collectors.toCollection(() -> new TreeSet()<>(Comparator.comparing(TerpAccountListV::getRegistryId))));
But this will make a Single Set having registry ID.
How will i remove element from above List using this set in Java 8?
First, count the occurrence by RegistryId in list. Then create a set of a non-duplicate items' RegistryId
Set<Integer> set =
list.stream()
.collect(Collectors.groupingBy(TerpAccountListV::getRegistryId,
Collectors.counting()))
.entrySet().stream()
.filter(e -> e.getValue() == 1L)
.map(e -> e.getKey())
.collect(Collector.toSet());
Then filter the list if RegistryId contains in set
List<TerpAccountListV> res = list.stream()
.filter(e -> set.contains(e.getRegistryId()))
.collect(Collector.toList());
Update:
You can do set creation part this way also
Set<Integer> track = new HashSet<>();
Set<Integer> set = new HashSet<>();
for (Integer item : list) {
if(!track.add(item.getRegistryId())) {
set.remove(item.getRegistryId());
} else {
set.add(item.getRegistryId());
}
}

Can I assign position of item in list?

ex = ['$5','Amazon','spoon']
I want to re-order this list, website - item - price.
Can I assign the index, for instance, ex.index('Amazon') = 1?
I'd like the result to be ['Amazon','spoon','$5']
I found information on how to swap positions, but I would like to know if I can assign an index for each item myself.
You cannot assign an index to an item, but you can build a permuted list according to a permutation pattern:
ex = ['$5','Amazon','spoon']
order = [1, 2, 0]
ex_new = [ex[i] for i in order]
print(ex_new)
#['Amazon', 'spoon', '$5']
Alternatively, you can overwrite the original list in place:
ex[:] = [ex[i] for i in order]
print(ex)
#['Amazon', 'spoon', '$5']

How to get value from list using index?

I have to try to get one by one value from list using index and i have try to get index value and update my stage one by one and respectively.
my python code below :
for ress in status_list:
print"res", ress
#self.workflow_stages = ress
if ress:
self.workflow_stages = ress
for index, item in enumerate(status_list):
print "test::", index
index_init = index
print"index_init:::", index_init
next = index_init + 1
print "next", next
lent = len(status_list)
print"lent", lent
return True
Thanks.
This for index, item in enumerate(status_list): means that index variable holds your respective index of the status_list and item variable holds your value. So in given for loop, item will hold the value of the corresponding index.
Generally, if you don't use the enumerate functionality to iterate over a list, you can access a value of the list like this status_list[index]

How to get element in specific index from NSMutable dictionary (Swift 3)

I need to get the first element from NSMutable dictionary. I tried to get the element using for loop. but I am not getting the correct element because the Dictionary does not follow order. Is there any way I can get the element?
Here is my code:
for (count, i) in myMutableDict.enumerated() {
if count == 2 {
print(i.key)
}
}
As you know dictionary is un ordered collection Type.
let dictionary:Dictionary = ["YYZ": "Toronto Pearson", "DUB": "Dublin"];
for(index,obj) in dictionary.enumerated() {
print("index- \(index) - Object- \(obj)");
print("key- \(obj.key) - value- \(obj.value)");
}
Enumeration will provide you index and Objects of dictionary as above code says. If you want to work with index then you need to get all keys and keep it sorted so that you can get your key by providing index. And from that key you can get value from dictionary object. Piece of code is given below.
var keyList = Array(dictionary.keys);
keyList = keyList.sorted();
print("keyList \(keyList)");
let keyAtIndex = keyList[1];
print("value = \(dictionary[keyAtIndex]!)");

Html agility pack tag selection

I need to process list tags in order to extract data from them. The problem is that I need to analyze each list separably. I tried something like this:
List<HtmlAgilityPack.HtmlNode> tl = new List<HtmlNode (doc1.DocumentNode.SelectNodes("//ul"));
I was expecting that every tl element will be separate ul list, but it turns out that tl has only one element containing all li tags in html document. What am I doing wrong?
I've solved the problem with following code:
foreach (HtmlAgilityPack.HtmlNode node in tk)
{
if (node.ParentNode.Name == "ul" || node.ParentNode.Name == "ol")
{
List<string> sh=new List<string>();
var t = node.ParentNode.Elements("li");
for(int i=0;i <t.Count();i++)
sh.Add(t.ElementAt(i).InnerText);
uoList.Add(sh);
}
}
Now every uoList list member represents an ul or ol element which contains all li element's inside that element.