如何使用jquery打开水晶报告以防止回发?

时间:2017-11-28 14:08:27

标签: jquery asp.net crystal-reports

我们有应用程序,我们使用Jquery创建了所有保存更新和删除代码,以防止回发。但现在我们在打开水晶报告时面临问题。 我们试图在互联网上找到类似的代码但不能。

我们无法从ASPX页面传递web方法中的水晶报表查看器ID。

请在下面的jquery代码中找到。

<script type="text/javascript">
       $(document).ready(function () {
           $("#btnprint").click(function () {
               var param = { grpval1: $('#txtbatchid').val() };
               $.ajax({
               type: "POST",
                   url: "frmelectbatchdsptch.aspx/PrintData",
                   data: JSON.stringify(param),
                   contentType: "application/json; charset=utf-8",
                   dataType: "json",
                   success: function (data) {

                   }
                   //
               });
           })
       });
</script>

请参阅下面的[网络方法],我们用它来打开水晶报告。

[Web Method]
       public static void PrintData(string grpval1)
       {
           //public static string PrintData(string param)
           //{
           SqlConnection sqlcon = new DBConnection().testconnection();
           DBConnection objmain = new DBConnection();
           DataTable dt = new DataTable();
           saveData cust = new saveData();
           String data = "Sp_Electdsptchprint'" + grpval1 + "','" + cust.strfinancialyr + "','" + cust.strbranchname + "','" + cust.strfcompid + "'";
           dt = objmain.Databaseselection(data);
           ReportDocument rptdoc = new ReportDocument();
           rptdoc.Load(System.Web.Hosting.HostingEnvironment.MapPath("~/Reports/Electdsptchprint.rpt"));
           rptdoc.SetDataSource(dt);
           rptdoc.SetParameterValue("@txtbatchid", grpval1);
           rptdoc.SetParameterValue("@finyearid", cust.strfinancialyr);
           rptdoc.SetParameterValue("@branchid1", cust.strbranchname);
           rptdoc.SetParameterValue("@CompanyID", cust.strfcompid);
           //string Reporttitle = Request.QueryString["Reporttitle"];
           //rptdoc.SummaryInfo.ReportTitle = Reporttitle;
           string GserverName = ConfigurationManager.AppSettings["GserverName"];
           string GDbUser = ConfigurationManager.AppSettings["GDbUser"];
           string GDbpwd = ConfigurationManager.AppSettings["GDbpwd"];
           string GDbname = ConfigurationManager.AppSettings["GDbname"];
           rptdoc.SetDatabaseLogon(GDbUser, GDbpwd, GserverName, GDbname, false);
           if (HttpContext.Current != null)
           {
               Page page = (Page)HttpContext.Current.Handler;
               CrystalReportViewer cry = (CrystalReportViewer)page.FindControl("CrystalReportViewer1");
               cry.ReportSource = rptdoc;
               cry.DataBind();
           }
           CrystalReportViewer1.ReportSource = rptdoc;
           ConnectionInfo cnnInfo = new ConnectionInfo();
           cnnInfo.ServerName = GserverName;
           cnnInfo.DatabaseName = GDbname;
           cnnInfo.UserID = GDbUser;
           cnnInfo.Password = GDbpwd;

           foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in rptdoc.Database.Tables)
           {

               TableLogOnInfo tli = tbl.LogOnInfo;
               tli.ConnectionInfo = cnnInfo;
               tbl.ApplyLogOnInfo(tli);
           }
           Session["Report"] = rptdoc;
       }

我们收到错误

对象引用未设置为对象的实例

任何人都可以帮忙解决这个问题。

先谢谢。 问候, iCanopus技术

0 个答案:

没有答案