fizsoft 发表于 2015-9-23 11:07:00

LocateDataSource事件不触发

一个月前写好的一段代码,当时执行是完全没有问题的,昨天重新打开,运行时报表控件报错“ 不支持所指定的方法。”,跟踪调试发现WebViewer控件的LocateDataSource事件代码没有被执行,把事件绑定语句写在Page_load事件里也是不行。
页面的所有代码:


public partial class PrtAllo : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
      {
            LoadPageReport();
            if (System.Web.HttpContext.Current.Request.QueryString["IDS"] != null)
            {
                HiddenField1.Value = System.Web.HttpContext.Current.Request.QueryString["IDS"];
            }
            else
            {
                HiddenField1.Value = "0";
            }
            WebViewer1.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(WebViewer1_LocateDataSource);
      }

      private void LoadPageReport()
      {
            GrapeCity.ActiveReports.PageReport report1 = null;
            report1 = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("/Print/AllocationSheet.rdlx")));
            WebViewer1.Report = report1;
      }

      protected void WebViewer1_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
      {
            string connStr = ConfigurationManager.ConnectionStrings["sqlconn"].ConnectionString;
            string ids = HiddenField1.Value;
            if (ids.EndsWith(","))
            {
                ids = ids.Substring(0, ids.Length - 1);
            }
            string querySQL = "select * from view_allocationsheetdetail where as_id in("+ids+")";
            DataSet ds = new DataSet();
            LoadDataToDataSet(connStr, querySQL, ds, "Table1");
            args.Data = ds.Tables;
      }

      private void LoadDataToDataSet(string connStr, string productSql, DataSet dataSetData, string tableName)
      {

            SqlConnection conn = new SqlConnection(connStr);
            SqlCommand cmd = new SqlCommand(productSql, conn);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = cmd;
            adapter.Fill(dataSetData, tableName);
      }

    }

frank.zhang 发表于 2015-9-23 12:10:00

您好,
从您的代码没有发现任何问题,怀疑是报表设置。您可以确认以下两点:
1.数据源为Dataset



2.数据集的SQL为空

fizsoft 发表于 2015-9-23 16:28:00

回复 2楼frank.zhang的帖子

谢谢,果然是报表文件设置的问题,我在报表文件里指定了sql语句。
另外我发现不报错的情况下,LocateDataSource事件是不用手动绑定的,自动会执行,我前面没有跟踪到是因为在执行LocateDataSource事件之前就已经抛出错误了。
可以结贴了,谢谢

frank.zhang 发表于 2015-9-23 17:50:00

感谢您的反馈。
页: [1]
查看完整版本: LocateDataSource事件不触发