sql - SSRS - 动态隐藏列时保持表格相同的宽度?

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

问候。

我有一份 SSRS 2005 报告,显示了元素的价格。对于某些客户,我从表中隐藏了一列(使用“可见性 - 隐藏”属性上的表达式)。

当我这样做时,我的 table 会缩小。我花了很长时间努力寻找一种动态调整该表大小的方法(或者在设计时做一些事情以使其保持相同的宽度),但我被困住了。

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

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

最佳答案

我知道如何实现此目的的唯一方法是在运行时更改 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

关于sql - SSRS - 动态隐藏列时保持表格相同的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1440381/

相关文章:

带组的 SQL Order By 子句

sql-server-2005 - 我应该向小表添加索引吗?

sql - 使用 Oracle SQL Developer 作为我的客户端时如何为 SQL Server 调用 sp_help [table]

sql - 业务规则使用检查约束好不好

sql - 将 Epoch 时间戳转换为 sql server(人类可读格式)

sql - 将 SQL Server 数据库设置为仅允许符合 ANSI 的 SQL 代码

MySQL、MSSql、甲骨文 : When to use which?

sql - 如何在单独的列中更新 SQL 查询的结果

mysql - 如何使用 SQL join 从闭包表中提取子 ID 和名称

java - 使用注释的 native hibernate/jpa 查询中标量值的问题