0

我在 jquery 中调用这个静态 web 方法,并在 jquery 的帮助下填充表格数据成功显示在表格中。在网页表单页面中有一个下拉菜单和两个日期选择器(从日期到日期),根据这些值的选择数据现在显示在表格中我想在点击导出按钮然后点击表格数据时创建水晶报告,下拉值和日期选择器值将显示在报告中

我将 dt 存储在会话中并调用想要在水晶报告中调用的人,并在水晶报告中添加水晶报告查看器

我有网络静态网络方法,即

[WebMethod]
public static string search_data(DateTime fromdate, DateTime todate, string region)
{
        try
        {
            string result = "";
            Ts1 td = new T1();
            DateTime frDate = new DateTime(fromdate.Year, fromdate.Month, fromdate.Day, 0, 0, 0);
            DateTime to_Date = new DateTime(todate.Year, todate.Month, todate.Day, 23, 59, 59);
            List<griddataresult_Result> dq = td.griddataresult(frDate, to_Date, region).ToList();

                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("OwnerName", typeof(string));
                dt.Columns.Add("RegNo", typeof(string));
                foreach (var c in dq)
                {

                    dt.Rows.Add(c.ID, c.OwnerName, c.RegNo);
                } 

             DataTable dtt= (DataTable)HttpContext.Current.Session["datagrid"];               
                result = DataSetToJSON(dt);              
            return result;
        }
        catch (Exception)
        {
            throw new Exception();
        }
 }

更新

现在我在网络表单中添加这个

private void BindReport(ReportDocument crystalReport, DateTime fromdate, DateTime todate, string region)
    {


        TrackDataEntities1 t = new TrackDataEntities1();
        crystalReport.Load(Server.MapPath("data.rpt"));
        List<griddataresult_Result> dsc = t.griddataresult(fromdate, todate, region).ToList();
        crystalReport.SetDataSource(dsc);
        CrystalReportViewer1.ReportSource = crystalReport;
    }
    protected void Report_Click(object sender, EventArgs e)
    {

        DataTable dt = Session["datagrid"] as DataTable;
        ReportDocument crystalReport = new ReportDocument();
        //crystalReport.SetParameterValue("@fromdate", fromdate.Value);
        //crystalReport.SetParameterValue("@todate", todate.Value);
        //crystalReport.SetParameterValue("@region", regiondrop.SelectedValue);
        BindReport(crystalReport,Convert.ToDateTime(fromdate.Value), Convert.ToDateTime(todate.Value), regiondrop.SelectedValue);

    }

当我点击搜索然后显示表格数据然后当我点击报告按钮表格消失并显示空白报告

4

1 回答 1

0

只需在 ButtonClick 事件中添加以下代码

 protected void Button5_Click(object sender, EventArgs e)
     { 
    dynamic rpt = new ReportDocument();
    ApplyCRLogin(rpt);
    DataSet dtu = new DataSet();
        // Your Stored Procedure Here 
       // Bind dtu to the ObjReport
       rpt .Database.Tables["Command"].SetDataSource(dtu.Tables[0]);
     // Here Command is name which you can see inside Field Explorer in Crystal Report Design Mode 
       // Then Pass your SP parametrs 
        rpt.SetParameterValue("@dtFromDate", txtFromDate.Text);
        rpt.SetParameterValue("@dtToDate", txtToDate.Text);

        //After this Export your Crstal Report  to  PDF
      ExportToPDF(rpt);
     }

     public void ApplyCRLogin(CrystalDecisions.CrystalReports.Engine.ReportDocument oRpt)
            {
                CrystalDecisions.CrystalReports.Engine.Database oCRDb = oRpt.Database;
                CrystalDecisions.CrystalReports.Engine.Tables oCRTables = oCRDb.Tables;
                CrystalDecisions.Shared.TableLogOnInfo oCRTableLogonInfo;
                CrystalDecisions.Shared.ConnectionInfo oCRConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
                oCRConnectionInfo.DatabaseName = "DatabaseName";
                oCRConnectionInfo.ServerName = "DBSRV_NAME";
                oCRConnectionInfo.UserID = "UserID";
                oCRConnectionInfo.Password = "Password";
                foreach (CrystalDecisions.CrystalReports.Engine.Table oCRTable in oCRTables)
                {
                    oCRTableLogonInfo = oCRTable.LogOnInfo;
                    oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
                    oCRTable.ApplyLogOnInfo(oCRTableLogonInfo);
                }
            }

如何将水晶报表导出为 PDF

于 2016-08-09T09:12:13.803 回答