Webform下开发rdlc报表实现钻取功能!

来源:互联网 发布:表格含公式,数据透视表 编辑:程序博客网 时间:2024/05/27 00:30

Webform下开发rdlc报表实现钻取功能!  

2009-10-22 20:06:08|  分类:C#.net |  标签:|字号 订阅

 

参考了蜡人张的blog

http://www.cnblogs.com/waxdoll/archive/2006/06/23/434215.html

学着做了一下rdlc Drillthrough报表,但用winform的方法始终不能在webform中成功,点击链接后提示没有为"主报表的数据源"提供数据源实例,解决方法是需要在drillthrough事件函数中再绑定一次主表数据源...

 

   CustomerInfo GI = new CustomerInfo();
    DataSet ds = new DataSet();
  private DataTable LoadEmployeesData()
    {
        string strConn = ConfigurationManager.AppSettings["ConnectionString"].ToString(); ;
        SqlConnection conn = new SqlConnection(strConn);
        conn.Open();

        string strSql = "select * from tb_CustomerAnswer ";
        SqlCommand cmd = new SqlCommand(strSql, conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds,"1");
        conn.Close();


       
       
        return ds.Tables["1"];
    }

    private DataTable LoadDepartmentsData()
    {
        string strConn = ConfigurationManager.AppSettings["ConnectionString"].ToString(); ;
        SqlConnection conn = new SqlConnection(strConn);
        conn.Open();

        string strSql = "select * from tb_CustomerInfo ";
        SqlCommand cmd = new SqlCommand(strSql, conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds,"2");
        conn.Close();
        return ds.Tables["2"];
    }


    protected void ReportViewer1_Drillthrough(object sender, DrillthroughEventArgs e)
    {
      
        

        LocalReport Report = (LocalReport)e.Report;
      
        Report.DataSources.Add(new ReportDataSource("dsCustomerInfo_tb_CustomerAnswer",
                LoadEmployeesData()));
        Report.DataSources.Add(new ReportDataSource("dsCustomerInfo_tb_CustomerInfo",
                LoadDepartmentsData())); //这里是必须的,浪费了好长时间
          
       
    }
    protected void Page_Load(object sender, EventArgs e)
    {
      
        if (!IsPostBack)
        {
         
            // Supply a DataTable corresponding to each report data source.
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("rptCustomerInfo.rdlc");
            ReportViewer1.LocalReport.DataSources.Add(
                new ReportDataSource("dsCustomerInfo_tb_CustomerInfo", LoadDepartmentsData())); 
                    }
       
        ReportViewer1.Drillthrough += new DrillthroughEventHandler(ReportViewer1_Drillthrough);
       
       
      
    }

 

原创粉丝点击