0

我的页面上有一个下拉列表、一个标签和一个 CR 查看器。当我从 DD 中选择报告时,我会更新标签以显示当前选择的报告,并更新 CRV 以显示报告。

标签更新很好,我只是把它放在那里作为测试,以确保其他控件正确更新。另一方面,CRV 总是落后一个请求。我选择了一份报告,但它没有显示出来。我选择了另一份报告,然后出现了我之前选择的报告。

下面发布的代码来自我添加标签之前的代码,但没有其他任何更改。

using System;
using DataAccess;
using CrystalDecisions.CrystalReports.Engine;

namespace Reporting
{
    public partial class CRViewer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            ReportDropDown.Items.Add("Select a report");

            var reports = Data.ExecutSql("select * from ngmasterdb..reports");
            while (reports.Read()) ReportDropDown.Items.Add(reports["Name"].ToString());
            reports.Close();
        }

        protected void ReportDropDown_SelectedIndexChanged(object sender, EventArgs e)
        {
            var reportInfo = Data.ExecutSql("select * from ngmasterdb..reports where Name = '" + ReportDropDown.SelectedValue.Replace("'", "''") + "'");

            try
            {
                ReportDocument rptdoc = new ReportDocument();

                if (!reportInfo.Read()) return;
                var file = reportInfo["ReportFile"].ToString();
                if (file == null || file.Trim() == "") return;

                ReportSource.Report.FileName = file;
                CrystalReportViewer1.RefreshReport();
            }
            finally
            {
                reportInfo.Close();
            }
        }
    }
}

我相信对 aspx 唯一感兴趣的是,对于 DropDown 控件,AutoPostBack 设置为 true。如果您仍然想查看 aspx,请告诉我,我会发布它。

4

1 回答 1

0

最初我基本上是这样做的:

ReportSource.Report.FileName = rptFileName;
CrystalReportViewer1.ReportSource = ReportSource;

当我摆脱 ReportSource (一个 CrystalDecisions.Web.CrystalReportSource 对象)并这样做时:

CrystalReportViewer1.ReportSource = rptFileName;

然后它开始正常运行。我之前曾尝试过这种方法(或者至少我有信心这样做了,尽管现在看起来不是这样......)但是在文件路径方面遇到了一些错误。

我不知道为什么我在尝试此操作时遇到了以前的错误,而且我仍然不知道为什么即使使用我尝试的方法控制也不能正确运行,所以如果有人有任何关于此的信息,请随意提示我。

于 2012-04-24T23:26:56.273 回答