我有一個SSRS 2005報告,顯示物品的價格。對於某些客戶,我從表格中隱藏一列(在可見性 - 隱藏屬性上使用表達式)。
當我這樣做,我的表縮小。我搜索了很長時間並且很難找到動態調整這個表的方法(或者在設計時做一些事情來使它保持相同的寬度),但是我被卡住了。
簡單地說'你不能這樣做'的答案不會幫助我。我已閱讀: http://forums.asp.net/t/1354956.aspx
我希望SO社區的一些聰明的靈魂有我的解決方法。謝謝!
我有一個SSRS 2005報告,顯示物品的價格。對於某些客戶,我從表格中隱藏一列(在可見性 - 隱藏屬性上使用表達式)。
當我這樣做,我的表縮小。我搜索了很長時間並且很難找到動態調整這個表的方法(或者在設計時做一些事情來使它保持相同的寬度),但是我被卡住了。
簡單地說'你不能這樣做'的答案不會幫助我。我已閱讀: http://forums.asp.net/t/1354956.aspx
我希望SO社區的一些聰明的靈魂有我的解決方法。謝謝!
我知道如何做到這一點的唯一方法是在運行時改變RDLC文件。基本上,您可以將RLDC文件加載到內存中(它只是一個XML文件),找到包含表格寬度的XML節點 - 然後修改內存中的設置。完成之後,您可以使用內存中加載的RDLC文件刷新reportViewer控件。
是的,我已經這樣做了,它確實有效。
--- EDIT ---以下代碼示例是通過其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
是否希望調整所有列的大小以便在特定列不可見時覆蓋整個表格? – shahkalpesh 2009-09-17 18:02:07
這將工作。我會解決調整1或2列。我只需要這張桌子的寬度相同。 – JoeB 2009-09-17 18:42:42