Infopath重复表-从当前行获取字段 [英] Infopath repeating table - get field from current row

查看:88
本文介绍了Infopath重复表-从当前行获取字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Infopath中有一个重复表.在发生字段更改事件时,我需要对相关行中的数据执行计算.我该如何在C#和Xpath隐藏代码中解决这个问题?

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?

推荐答案

您可以为此使用XPathNodeIterator.例如: 您可以为此使用XPathNodeIterator.例如:

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;

这篇关于Infopath重复表-从当前行获取字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆