搜尋此網誌

2011-12-13

CrystalReportViewer匯出失敗

無法使用指定的選項來匯出。請檢查您的選項,然後再試一次。
Failed to export using the options you specified. Please check your options and try again.

因為按下匯出時,會postback,需要再做一次資料繫結.
protected void Button_Click(object sender, EventArgs e)
        {
            DataSet ds = LoadData();
            
            ReportDocument Report2 = new ReportDocument();
            string reportPath = Server.MapPath(@".\App_Data\CrystalReport2.rpt");

            Report2.Load(reportPath);
            Report2.SetDataSource(ds);

            CrystalReportViewer1.ReportSource = Report2;
            Session.Add("report", Report2);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //處理Viewer匯出
            if (Page.IsPostBack && Session["report"] != null)
            {
                CrystalReportViewer1.ReportSource = Session["report"];
            }   
        }

參考
Report dissapear on postback
How to use "Print" and " Export" option from CrystalRep

沒有留言: