循环通过infopath 2010重复部分并使用C#以相反的顺序显示数据

时间:2013-08-21 07:34:49

标签: c# visual-studio-2010 infopath infopath2010

我是c#的总菜鸟。我有一个在InfoPath 2010中创建的表单,后面有c#代码。此表单的目的是成为我们在此处理的问题的运行日志。 C#用于生成格式特别严格的电子邮件。此电子邮件的正文需要以相反的顺序显示重复字段中的项目(最新的顶部)。我的第一个问题是试图找到一种方法来将重复部分的数据填充到电子邮件正文中。我终于能够找到这个以标准顺序成功打印数据的foreach循环。

foreach (XPathNavigator node in runningLogTable)
{
    logEntry = node.SelectSingleNode("@my:entry", this.NamespaceManager).Value;
    logTime = node.SelectSingleNode("my:CurrentTime", this.NamespaceManager).Value;
    sb.Append(convertTime(logTime) + "\n");
    sb.Append(logEntry + "\n\n");
}

来源:Infopath repeating table - get field from current row

顺便说一句,这个循环在stringBuilder函数内部。我的问题是,我该如何以相反的顺序执行此操作? 我已经谷歌搜索了好几天,我不知道我是否只是不知道正确的术语或什么,但不用说,我无法找到一个有效的解决方案。我知道必须有一个我只是没有看到的简单解决方案。

非常感谢任何帮助!!

1 个答案:

答案 0 :(得分:0)

不确定为什么这个问题从网格中消失了,但是有一些人帮我(特别是保存)让我走上了不同的道路。我能够使用以下代码来使用我的代码:

            //Lets get those log entries!
        List<string> logEntries = new List<string>(); // Create a list array to hold each entry
        List<string> logTimes = new List<string>(); // Create a list array to hold each log time

        foreach (XPathNavigator entry in runningLogTable) // iterate through the repeating section of the log
        {
            logEntry = entry.SelectSingleNode("@my:entry", this.NamespaceManager).Value; // Get the string value from each field
            logTime = entry.SelectSingleNode("my:CurrentTime", this.NamespaceManager).Value; // Get the string value for the time from each field.
            logEntries.Add(logEntry); // Add each log entry to the list starting at position (index) 0
            logTimes.Add(convertTime(logTime)); // Add each time entry to the list starting at position (index) 0
            // Each log entry should align with the correct time entry since both start at index 0.
        }
        for (int i = (logEntries.Count - 1); i >= 0; i--) // get the count of the log entries list and loop through each indexed position in reverse.
        {
            sb.Append(logTimes[i].ToString() + "\n"); // append each indexed entry to the log starting from the last position and moving to the first (0)
            sb.Append(logEntries[i].ToString() + "\n\n"); // append each indexed time to the log starting from the last position and moving to the first (0)
        }

感谢所有帮助过的人。我希望我可以链接到用户名,因为保存确实拯救了我!

谢谢大家!!

相关问题