一尘不染

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

sql

你好。

我有一份SSRS 2005报告,其中显示了物价。对于某些客户,我在表中隐藏了一列(在“可见性-隐藏”属性上带有表达式)。

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

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

我希望SO社区的一些聪明人对我有用。谢谢!


阅读 164

收藏
2021-03-10

共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
2021-03-10