我对SSRS很新,并且一直坚持传递参数。目前我正在做以下事情:
ReportViewer1.ServerReport.ReportPath = ConfigurationManager.AppSettings["serverPath"] + "MyReport";
List<ReportParameter> paralist = new List<ReportParameter>();
ReportParameter reportParam1 = new ReportParameter("LocationId", txtLocationId.Text);
ReportParameter reportParam2 = new ReportParameter("PrdAcctId", txtProductAccountId.Text);
ReportParameter reportParam3 = new ReportParameter("FromDate", frmdt);
ReportParameter reportParam4 = new ReportParameter("ToDate", todt);
ReportParameter reportParam5 = new ReportParameter("IntAmt", todt);
paralist.Add(reportParam1);
paralist.Add(reportParam2);
paralist.Add(reportParam3);
paralist.Add(reportParam4);
paralist.Add(reportParam5);
ReportViewer1.ServerReport.SetParameters(paralist);
当没有时,这很好用。参数设置。但在某些情况下,没有。参数将根据用户输入在运行时决定。
现在,我对如何制造否则感到茫然。 .rdl文件中的参数灵活。例如,根据用户输入,可以有n个FromDate和ToDate以及相应的IntAmt。
我很感激您的帮助,并提前致谢。
答案 0 :(得分:0)
您可以调用GetParameters方法获取所有当前报表参数并循环遍历它们以查看每个参数的含义以及每个参数的各种属性:
开始于:
ReportParameterInfoCollection param = ReportViewer1.ServerReport.GetParameters();
答案 1 :(得分:0)
您可以尝试以下操作,它可以 - 使用参数的序数值替换索引0:
if (this.rptView.ServerReport.GetParameters()[0].Values.Count > 0)
{
string parvalue = this.rptView.ServerReport.GetParameters()[0].Values.ToString();
paramList.Add(new ReportParameter("ReportName", parvalue));
}
答案 2 :(得分:0)
这不是您问题的直接答案。我们的主页面使用window.href
重定向到报表呈现页面,并将参数作为查询字符串传递。
注意:这是VB.Net代码,您可以将其转换为等效的C#代码
代码背后
Public Function GetParametersList(ByVal reportRDLName As String) As List(Of String)
'Get these values from database. Following is a sample
Dim parametersList As New List(Of String)()
parametersList.Add("plantcd")
parametersList.Add("CountID")
Return parametersList
End Function
Public Function GetReportPath(ByVal reportRDLName As String) As String
'Get these values from database. Following is a sample
Dim reportPath As String = "/MyFolder/MyModule/"
Return reportPath
End Function
Protected Overrides Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
'--------------------------------------------------------
Me.EnableViewState = True
If Not Page.IsPostBack Then
vwreports.ServerReport.ReportServerCredentials = New MyCustomReportServerCredentials
vwreports.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
vwreports.ServerReport.ReportServerUrl = New Uri(ConfigurationManager.AppSettings("MyReportServer"))
Dim reportRDLName As String = Request.QueryString("rname").ToString()
Dim parametersList As List(Of String) = GetParametersList(reportRDLName)
Dim reportPath As String = GetReportPath(reportRDLName)
Dim countOfParameters As Integer = parametersList.Count
Dim parms As ReportParameter() = New ReportParameter(countOfParameters - 1) {}
Dim iterationCount As Integer = 0
For Each parameterName As String In parametersList
Dim parameterValue As String = Convert.ToString(Request.QueryString(parameterName))
If Not [String].IsNullOrEmpty(parameterValue) Then
parms(iterationCount) = New ReportParameter(parameterName, parameterValue)
iterationCount += 1
End If
Next
vwreports.ServerReport.ReportPath = reportPath + reportRDLName
vwreports.ServerReport.SetParameters(parms)
vwreports.ShowParameterPrompts = False
vwreports.ServerReport.Refresh()
End If
End Sub