【问题标题】:How to display fields in new line in same textBox?如何在同一文本框中的新行中显示字段?
【发布时间】:2012-03-29 06:20:38
【问题描述】:

我正在使用 Silverlight4 和 Telerik Reporting Q3 2011。我正在尝试生成所有网点的报告。 我使用 Table 来显示它的字段。我想在同一个单元格中显示完整地址。 我怎么可能?

我使用以下表达式在同一单元格中显示完整地址。

 = Fields.AddressLine1
     + ", " + Fields.AddressLine2
     + ", " + Fields.Suburb
     + ", " + Fields.City
     + ", " + Fields.State
     + ", " + Fields.Country

我想在同一个单元格中显示它,但希望输出如下所示..

 =====================
       Address
 =====================
  15A,
  xxxx xxxRoad,
  xxxxxx,
  xxxxxxxx
 ====================

但我明白了

 =====================
       Address
 =====================
  15A, xxxx xxxRoad, xxxxxx, xxxxxxxx
 =====================

如何获得我想要的输出?

【问题讨论】:

    标签: c# silverlight-4.0 telerik telerik-reporting


    【解决方案1】:

    使用 Environment.NewLine 进入新行,见下文

    =Fields.AddressLine1 + ", " 
    + Environment.NewLine + Fields.AddressLine2 + ", " 
    + Environment.NewLine + Fields.Suburb + ", " 
    + Environment.NewLine + Fields.City + ", " 
    + Environment.NewLine + Fields.State + ", " 
    + Environment.NewLine + Fields.Country;
    

    编辑

    参考链接how to insert a newline in Textblock in silverlight

    【讨论】:

    • 它显示错误“表达式包含当前上下文中未定义的对象'环境'”。
    • 在顶部使用命名空间“using System”。
    • 你把命名空间放在哪里,把 using System 放在命名空间声明处。
    【解决方案2】:

    您是否尝试过在字符串中使用\n\r\n 进行换行?

    【讨论】:

    • 我试过了,但没用 我也试过 Environment.NewLine 但也没用
    • 当使用 \n 或 \r 时,它向我显示错误 '\r \n\' 未在当前上下文中定义
    • 您确实将 \r\n 放在逗号之后,双引号之间吗? Environment.Newline 应该可以解决问题(在引号之外),奇怪的是它没有。所以 Fields.AddressLine1 + ", \r\n" + Fields.AddressLine2Fields.AddressLine1 + ", " + Environment.Newline + Fields.AddressLine2
    • 也许您必须检查 MultiLine 属性?例如,在 Visual Studio 中,您需要对文本框执行此操作
    • 如果我在引号之间使用 \r\n ,它会将 \r\n 显示为文本。
    【解决方案3】:

    是的,明白了.....

    我在这个函数中做了函数NewLineFeeds()我使用了Replace()方法将特定字符串替换为newLine(\n)。

     public static string NewLineFeeds(string text)
        {
            string result = text.Replace(", ", "\n");
            result = result.Replace(", ", "\n");
            result = result.Replace(", ", "\n");
            return result;
        }
    

    我的表情是

     =NewLineFeeds(Fields.AddressLine1 
     + ", " + Fields.AddressLine2 
     + ", " + Fields.Suburb 
     + ", " + Fields.City 
     + ", " + Fields.State 
     + ", " + Fields.Country)
    

    这会调用函数 NewLineFeeds() 并将“,”替换为 \n(新行)。 添加这将工作正常..

    【讨论】:

      【解决方案4】:

      使用全名System.Environment.NewLine 即可。 我刚刚在我的报告中确认了这一点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-24
        • 1970-01-01
        相关资源
        最近更新 更多