Winforms ReportViewer and setting parameters properly for ServerReport
I'm setting parameters fo开发者_运维百科r a report that I'm showing in ReportViewer control, and the parameters are setting properly and the report is running with the proper parameters, however the actual controls that provide the report criteria at the top of the ReportViewer are not selected. Why aren't the proper items selected in the criteria, even when the report is properly running with the criteria that I set?
ReportParameter month = new ReportParameter("month", "September 2011");
SsrsReportInfo reportInfo = new SsrsReportInfo("Summary", "http://server/ReportServer/", "/MyFolder/Summary", month);
this.reportViewer1.ServerReport.ReportPath = reportInfo.ReportPath;
this.reportViewer1.ServerReport.ReportServerUrl = new Uri(reportInfo.ReportServerUrl);
if (reportInfo.Parameters != null)
{
this.reportViewer1.ServerReport.SetParameters(reportInfo.Parameters);
}
this.reportViewer1.RefreshReport();
Here's the code for the reportInfo class:
/// <summary>
/// SSRS report information for report viewer.
/// </summary>
public class SsrsReportInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="SsrsReportInfo"/> class.
/// </summary>
/// <param name="reportName">Name of the report.</param>
/// <param name="reportServerUrl">The report server URL.</param>
/// <param name="reportPath">The report path.</param>
public SsrsReportInfo(string reportName, string reportServerUrl, string reportPath)
: this(reportName, reportServerUrl, reportPath, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SsrsReportInfo"/> class.
/// </summary>
/// <param name="reportName">Name of the report.</param>
/// <param name="reportServerUrl">The report server URL.</param>
/// <param name="reportPath">The report path.</param>
/// <param name="reportParameters">The report parameters.</param>
public SsrsReportInfo(string reportName, string reportServerUrl, string reportPath, params ReportParameter[] reportParameters)
{
this.ReportName = reportName;
this.ReportServerUrl = reportServerUrl;
this.ReportPath = reportPath;
this.Parameters = reportParameters;
}
/// <summary>
/// Gets or sets the name of the report.
/// </summary>
/// <value>The name of the report.</value>
public string ReportName
{
get;
set;
}
/// <summary>
/// Gets or sets the report server URL.
/// </summary>
/// <value>The report server URL.</value>
public string ReportServerUrl
{
get;
set;
}
/// <summary>
/// Gets or sets the report path.
/// </summary>
/// <value>The report path.</value>
public string ReportPath
{
get;
set;
}
/// <summary>
/// Gets or sets the parameters.
/// </summary>
/// <value>The parameters.</value>
public ReportParameter[] Parameters
{
get;
set;
}
}
Thanks,
Mark
I've figured out the issue here. I had the code setting the path, url, parameters and refreshing the report within a Form constructor. I moved it into the Form.Load event and it works fine now. Reports still run properly, but now the parameters are properly set also within the criteria portion on the top of the ReportViewer.
I had the same usage shown here: http://technet.microsoft.com/es-es/library/aa337089(SQL.90).aspx, however noticed that they did it in the Form.Load event, and I tried that, and it worked. I could probably do it in the ReportViewer.Load event also, the reason for this is probably that the controls aren't drawn up on screen yet before setting the values.
精彩评论