【问题标题】:SSRS - Keep a table the same width when hiding columns dynamically?SSRS - 动态隐藏列时保持表格相同的宽度?
【发布时间】:2009-09-17 17:57:22
【问题描述】:

您好。

我有一份 SSRS 2005 年报告,其中显示了物品的价格。对于某些客户,我会在表格中隐藏一列(在 Visibility - hidden 属性上使用表达式)。

当我这样做时,我的桌子缩小了。我一直在努力寻找一种动态调整此表大小的方法(或在设计时做一些事情以使其保持相同的宽度),但我被卡住了。

简单地说“你不能这样做”的答案对我没有帮助。我已经读过: http://forums.asp.net/t/1354956.aspx

我希望 SO 社区的一些聪明人能为我找到解决方法。谢谢!

【问题讨论】:

  • 是否要调整所有列的大小,以便在特定列不可见时覆盖整个表?
  • 那行得通。我会调整 1 或 2 列的大小。我只需要表格的宽度相同。

标签: sql sql-server sql-server-2005 reporting-services


【解决方案1】:

我知道如何做到这一点的唯一方法是在运行时更改您的 RDLC 文件。基本上,您可以将 RLDC 文件加载到内存中(它只是一个 XML 文件),找到包含表格宽度的 XML 节点 - 然后修改内存中的设置。完成后,您可以使用加载到内存中的 RDLC 文件刷新您的 reportViewer 控件。

是的,我已经这样做了,而且确实有效。

以下代码示例是通过其 XMLpath 更改内存中 RDLC 文件的数据。

  Private Sub ModifyRDLCInMemory()

    Dim xmlDoc As XmlDocument = New XmlDocument
    Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
    'create in memory, a XML file from a embedded resource
    Dim xmlStream As Stream = asm.GetManifestResourceStream(ReportViewer1.LocalReport.ReportEmbeddedResource)

    Try
      'Load the RDLC file into a XML doc
      xmlDoc.Load(xmlStream)
    Catch e As Exception
      MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    End Try

    'Create an XmlNamespaceManager to resolve the default namespace
    Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
    nsmgr.AddNamespace("nm", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition")
    nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner")

    'Loop through each node in the XML file
    Dim node As XmlNode
    For Each node In xmlDoc.DocumentElement.SelectNodes(String.Format("//nm:{0}[@rd:LocID]", "Value"), nsmgr)  'XPath to LocID node.. You will want to change this to locate your Table Width node. You may need to read up on XMLPath
      Dim nodeValue As String = node.InnerText  'Gets current value of Node
      If (String.IsNullOrEmpty(nodeValue) Or Not nodeValue.StartsWith("=")) Then
        Try
          node.InnerText = YOURNEWVALUE

        Catch ex As Exception
          'handle error
        End Try
      End If
    Next

    ReportViewer1.LocalReport.ReportPath = String.Empty
    ReportViewer1.LocalReport.ReportEmbeddedResource = Nothing
    'Load the updated RDLC document into LocalReport object.
    Dim rdlcOutputStream As StringReader = New StringReader(xmlDoc.DocumentElement.OuterXml)
    Using rdlcOutputStream
      ReportViewer1.LocalReport.LoadReportDefinition(rdlcOutputStream)
    End Using

  End Sub

【讨论】:

  • 这个问题非常有趣。我将再给它一个小时左右,如果没有人提出更好的解决方案,我会将您标记为答案。谢谢!
  • 如果你愿意,我可以通过一些 VB.NET 代码来帮助你。实际上我现在就去。
  • 已发布代码。如果您对此有任何疑问,请告诉我。我们曾经使用这种方法本地化我们的报告(在切换语言时更改数据)。我们现在动态生成我们的报告,所以我们不再使用它了。
  • 感谢这个例子。我快速实现了解析器来有条件地更改 Tablix 和 Rectangle 列的宽度。我还将向您介绍本地化文本的想法。为每个语言环境使用单独的报告有时很好,但是当您有动态文本时,您也需要动态报告文本。在外部执行此操作比提供报表内联功能更有效……您可以使用适当的编程语言,如 C# ?
【解决方案2】:

最好的选择是复制表格并将您要显示的列放在另一个表格的上方。然后你可以动态地设置表格的可见性。为了使它们可编辑,您将一个表比另一个小一点,以便在它高于一个时选择它。

【讨论】:

    猜你喜欢
    • 2010-10-08
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 2018-02-25
    • 2014-01-19
    • 2011-06-01
    相关资源
    最近更新 更多