I have a repeating table in Infopath. On a field change event, I need to execute a calculation to with data in the row in question. How do I go about this in the code-behind (C#) and Xpath?
For example, I have a start date and end date. In the code-behind the do a calculation to calculate the number of hours in the span. This works for the first row, but not subsequent rows. I know the way I wrote it so far only works for the first row, but how do I make this work for all rows?
You can use XPathNodeIterator for this. For example:
You can use XPathNodeIterator for this. For example:
XPathNodeIterator nodes = MainDataSource.CreateNavigator().Select("/my:myFields/my:group1/my:group2", this.NamespaceManager);
string field1 = string.Empty;
string field2 = string.Empty;
string field3 = string.Empty;
foreach (XPathNavigator node in nodes)
{
field1 = node.SelectSingleNode("my:field1", this.NamespaceManager).Value;
field2 = node.SelectSingleNode("my:field2", this.NamespaceManager).Value;
field3 = node.SelectSingleNode("my:field3", this.NamespaceManager).Value;
}
This will get the value of each field and set a string variable to that value. If you wish to concatenate all the values, you'll need to modify this -- you can do something very simple like:
field1 = node.SelectSingleNode("my:field1", this.NamespaceManager).Value + " " + field1;