Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
What is this page about?
This page explains how to use extension methods of iteration variables in template loops.
LINQ Reporting Engine provides special extension methods for iteration variables of any type. You can normally use these extension methods in template expressions. The following list describes the extension methods.
Returns the zero-based index of a sequence item that is represented by the corresponding iteration variable. You can use this extension method to distinguish sequence items with different indexes and then handle them in different ways. For example, given that items is an enumeration of the strings “item1”, “item2”, and “item3”, you can use the following template to enumerate them prefixing all of them but the first one with commas.
The items are: <<foreach [
item in items]>><<[item.IndexOf() != 0
? ", "
: ""]>><<[item]>><</foreach>>.
In this case, the engine produces a report as follows.
The items are: item1, item2, item3.
Returns the one-based index of a sequence item that is represented by the corresponding iteration variable. You can use this extension method to number sequence items without involving Microsoft Word® lists. For example, given the previous declaration of items, you can enumerate and number them in a document table using the following template.
| No. | Item |
| <<foreach [item in items]>><<[item.NumberOf()]>> | <<[item]>><</foreach>> |
In this case, the engine produces a report as follows.
| No. | Item |
|---|---|
| 1 | item1 |
| 2 | item2 |
| 3 | item3 |
Q: How can I obtain the position of the current item inside a foreach loop?
A: Use the IndexOf() extension method on the iteration variable. It returns a zero‑based index, so the first item is 0. Example: <<[item.IndexOf()]>>.
Q: How do I generate a sequential number for each item without using Word list numbering?
A: Call the NumberOf() extension method on the iteration variable. It returns a one‑based index (first item is 1). Example: <<[item.NumberOf()]>> can be placed in a table column to produce numbered rows.
Q: Can these extension methods be used with custom object types in the collection?
A: Yes. The methods are defined on the internal iteration wrapper, so they work with any collection element type—strings, custom classes, or structs. Simply reference item.IndexOf() or item.NumberOf() in the template regardless of the underlying object type.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.