找回密码
 立即注册

QQ登录

只需一步,快速开始

fizsoft

注册会员

16

主题

44

帖子

140

积分

注册会员

积分
140

活字格认证微信认证勋章

fizsoft
注册会员   /  发表于:2015-9-23 11:07  /   查看:4410  /  回复:3
一个月前写好的一段代码,当时执行是完全没有问题的,昨天重新打开,运行时报表控件报错“ 不支持所指定的方法。”,跟踪调试发现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[0];
        }

        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);
        }

    }

3 个回复

倒序浏览
frank.zhang
社区贡献组   /  发表于:2015-9-23 12:10:00
沙发
您好,
从您的代码没有发现任何问题,怀疑是报表设置。您可以确认以下两点:
1.数据源为Dataset



2.数据集的SQL为空

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

评分

参与人数 1满意度 +5 收起 理由
fizsoft + 5 问题解决,谢谢

查看全部评分

回复 使用道具 举报
fizsoft
注册会员   /  发表于:2015-9-23 16:28:00
板凳
回复 2楼frank.zhang的帖子

谢谢,果然是报表文件设置的问题,我在报表文件里指定了sql语句。
另外我发现不报错的情况下,LocateDataSource事件是不用手动绑定的,自动会执行,我前面没有跟踪到是因为在执行LocateDataSource事件之前就已经抛出错误了。
可以结贴了,谢谢
回复 使用道具 举报
frank.zhang
社区贡献组   /  发表于:2015-9-23 17:50:00
地板
感谢您的反馈。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部