Crystal报表查看器在单击工具栏(子报表任何内容)时再次询问参数,并返回显示相同的主页面

时间:2017-06-29 19:40:43

标签: c# asp.net crystal-reports

这是一个旧的应用程序 它显示网页上的水晶报告,但问题是,当我点击任何东西时它再次询问参数但显示相同的报告我不知道如何做到这一点因为如果我点击子报告同样要求参数并显示相同的报告

protected void Page_Load(object sender,EventArgs e)     {         if(!IsPostBack)         {

        var p = Request.QueryString["P"].ToString();
        var appId = int.Parse(Request.QueryString["appId"].ToString());
        var HE = new HIVAIDSEntities();
        var app = HE.ApplicatioNames.FirstOrDefault(x => x.Hivrp_app_name_pk == appId);



        //SQLReport report = new SQLReport();
        var report = new ReportDocument();
        //   Application.StartupPath 
        report.Load(filename: Server.MapPath(p));
        //Get SQL Server Details
        string zServer = app.Hivrp_server_name;
        string zDatabase = app.Hivrp_database_name;
        string zUsername = app.Hivrp_user_id;
        string zPassword = app.Hivrp_password;

        var ciReportConnection = new ConnectionInfo
        {
            ServerName = zServer,
            DatabaseName = zDatabase,
            UserID = zUsername,
            Password = zPassword
        };

        //TableLogOnInfo crTableLogoninfo = new TableLogOnInfo();
        //Assign data source details to tables

        foreach (CrystalDecisions.CrystalReports.Engine.Table table in report.Database.Tables)
        {

            table.LogOnInfo.ConnectionInfo = ciReportConnection;
            table.ApplyLogOnInfo(table.LogOnInfo);

        }


        //Assign data source details to the report viewer
        if (this.CrystalReportViewer1.LogOnInfo != null)
        {
            TableLogOnInfos tlInfo = this.CrystalReportViewer1.LogOnInfo;
            foreach (TableLogOnInfo tbloginfo in tlInfo)
            {
                tbloginfo.ConnectionInfo = ciReportConnection;
            }
        }
        CrystalReportViewer1.ReportSource = report;
        CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
        CrystalReportViewer1.DisplayPage = true;

        CrystalReportViewer1.RefreshReport();
        Session["ReportDocument"] = report;
    }
    else
    {
        ReportDocument doc = (ReportDocument)Session["ReportDocument"];
        CrystalReportViewer1.ReportSource = doc;
        CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
        CrystalReportViewer1.DisplayPage = true;

        CrystalReportViewer1.RefreshReport();

    }

1 个答案:

答案 0 :(得分:1)

我刚刚将Page_Load函数更改为Page_Init,一切正常。:)