Infopath repeating table - get field from current row

混江龙づ霸主 提交于 2020-01-14 05:09:47

问题


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?


回答1:


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;


来源:https://stackoverflow.com/questions/11477723/infopath-repeating-table-get-field-from-current-row

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!