我有一些 VB.net 代码,可以检索 SSRS 报告的所有报告参数。根据 MSDN 文档 ,Visible 和 PromptUser 属性应与报告是否显示该参数的提示相关(如果未提供,则仅显示错误)。然而,在此示例代码中,这些属性始终返回 true。该代码引用 MS.ReportViewer.WebForms dll。我已经尝试过版本 10 和 11。
Public Function GetReportParameters(strPath As String) As List(Of Microsoft.Reporting.WebForms.ReportParameterInfo)
Dim lstParams As New List(Of Microsoft.Reporting.WebForms.ReportParameterInfo)
Dim objRV As New Microsoft.Reporting.WebForms.ReportViewer
objRV.ServerReport.ReportServerUrl = New System.Uri("http://localhost/ReportServer/")
objRV.ServerReport.ReportPath = strPath
Dim oRptParams As Microsoft.Reporting.WebForms.ReportParameterInfoCollection = objRV.ServerReport.GetParameters
For Each oRptParam As Microsoft.Reporting.WebForms.ReportParameterInfo In oRptParams
Dim strName As String = oRptParam.Name
Dim blnPromptUser As Boolean = oRptParam.PromptUser
Dim blnVisible As Boolean = oRptParam.Visible
lstParams.Add(oRptParam)
Next
Return lstParams
End Function
我也尝试过使用 LocalReport 而不是 ServerReport,但没有帮助。正如您从报表生成器中的报表参数属性中看到的,有一个参数设置为隐藏。
我发现了同样的行为..奇怪但真实。
但出于我的目的(查看是否选择了Visible),我找到了一种解决方法。
选择隐藏时,报表设计器允许您输入提示,但它不会传递到
ReportParameterInfo
选择内部时,您甚至无法输入提示。
作为奖励,如果选择了 Visible,报表设计器会强制您输入提示。
所以我可以得出结论:当选择
Visible时,
ReportParameterInfo.Prompt
始终被填充。
if (param.Prompt == "")
{
// Parameter not "Visible"
}
else
{
// Parameter is "Visible"
}
If param.Prompt = "" Then
' Parameter not "Visible"
Else
' Parameter is "Visible"
End If