Winforms ReportViewer并正确设置ServerReport参数

本文关键字:设置 ServerReport 参数 ReportViewer Winforms | 更新日期: 2023-09-27 18:07:57

我正在为ReportViewer控件中显示的报告设置参数,参数设置正确,报告使用适当的参数运行,但是没有选择在ReportViewer顶部提供报告标准的实际控件。为什么没有在标准中选择适当的项,即使当报表按照我设置的标准正常运行时也是如此?

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();
下面是reportInfo类的代码:
/// <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;
    }
}

谢谢,马克

Winforms ReportViewer并正确设置ServerReport参数

我已经找到了这里的问题。我在Form构造函数中设置了路径、url、参数和刷新报告的代码。我把它移到Form中。加载事件,它现在工作正常。报告仍然可以正常运行,但是现在在ReportViewer顶部的criteria部分中也可以正确设置参数。

我在这里有同样的用法:http://technet.microsoft.com/es-es/library/aa337089(SQL.90).aspx,但注意到他们在表单中这样做。加载事件,我试过了,成功了。我可以在ReportViewer中做。加载事件,这样做的原因可能是控件在设置值之前还没有在屏幕上绘制。