499247203@qq.co 发表于 2017-6-27 16:27:45

ActiveReport +MVC +ajax 动态绑定数据源

以下是我绑定数据源的代码,现在我着需要根据页面传递的参数来绑定数据源
例如:DataTable tb = DBContext.ExecuteDataTable("SELECT Name,Sex,Age FROM Student");
前台传递一个id的参数   ,DataTable tb = DBContext.ExecuteDataTable("SELECT Name,Sex,Age FROM Student where id="+id);
根据不同的id获取不同的数据源,使用ajax 后 直接跳过pageDocument.LocateDataSource ,无法绑定,请问怎么通过参数来绑定不同数据源

public ActionResult Index()

      {
      GetReport();
      return View();
      }

      public void GetReport()
      {
      GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("/PageReport1.rdlx")));
      PageDocument pageDocument = new PageDocument(report);
      System.Action<object, LocateDataSourceEventArgs> action = new Action<object, LocateDataSourceEventArgs>(Document_LocateDataSource);
      pageDocument.LocateDataSource += (sender, args) =>
      {
          action(sender, args);
      };
      ViewData.Model = report;
      }

      private void Document_LocateDataSource(object sender, LocateDataSourceEventArgs args)
      {
      List<Student> list = new List<Student>();
      //
      DataTable tb = DBContext.ExecuteDataTable("SELECT Name,Sex,Age FROM Student");
      foreach (System.Data.DataRow row in tb.Rows)
      {
          Student stu = new Student();
          stu.Name = row["Name"].ToString();
          stu.Sex = row["Sex"].ToString();
          stu.Age = row["Age"].ToString();
          list.Add(stu);
      }
      int ss = args.Report.Parameters.Count();
      args.Data = list;
      }

499247203@qq.co 发表于 2017-6-27 16:45:01

hello大哥大姐们,来一发呀,新手,刚接触ActiveReport,不太懂,谢谢大家了!:)

Lenka.Guo 发表于 2017-6-27 18:07:26

如果与这个是同一个问题,刚已经回复过了哦。
http://gcdn.gcpowertools.com.cn/forum.php?mod=viewthread&tid=37973&extra=page%3D1
页: [1]
查看完整版本: ActiveReport +MVC +ajax 动态绑定数据源