Joe*_*oeB 9 sql sql-server sql-server-2005 reporting-services
问候.
我有一份SSRS 2005报告,显示了物品的价格.对于某些客户,我隐藏了表中的列(在Visibility - hidden属性上有一个表达式).
当我这样做时,我的桌子缩小了.我一直在寻找一种方法来动态调整这个表的大小(或者在设计时做一些事情让它保持相同的宽度),但是我被卡住了.
简单地陈述"你不能做到这一点"的答案对我没有帮助.我已经读过了: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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11331 次 |
| 最近记录: |