ReportViewer动态加载报表文件

/*页面上放置一个ReportViewer1和两个按钮ButtonBing,ButtonXian点不同的按钮ReportViewer1显示不同的报表文件(Reportxian.rdlc和Reportbing.rdlc)*/

protected   void  ButtonXian_Click( object  sender, EventArgs e)
    
{
      

        ControlCollection coll 
= ReportViewer1.Parent.Controls;
        
int oldIndex = coll.IndexOf(ReportViewer1);
        ReportViewer newViewer 
= new ReportViewer();
        coll.AddAt(oldIndex, newViewer);
        coll.Remove(ReportViewer1);

        newViewer.LocalReport.DataSources.Clear();

        newViewer.LocalReport.ReportPath 
= MapPath("Reportxian.rdlc");
        newViewer.LocalReport.ReportEmbeddedResource 
= "Reportxian.rdlc";
        ReportDataSource rpt 
= new ReportDataSource("DataSet1_ShowOneFruit", ds.Tables["table"]);
        newViewer.LocalReport.DataSources.Add(rpt);
        newViewer.LocalReport.Refresh();


    }

    
protected   void  ButtonBing_Click( object  sender, EventArgs e)
    
{

       
        ControlCollection coll 
= ReportViewer1.Parent.Controls;
        
int oldIndex = coll.IndexOf(ReportViewer1);
        ReportViewer newViewer 
= new ReportViewer();
        coll.AddAt(oldIndex, newViewer);
        coll.Remove(ReportViewer1);


        newViewer.LocalReport.DataSources.Clear();

        newViewer.LocalReport.ReportPath 
= MapPath("Reportbing.rdlc");
        newViewer.LocalReport.ReportEmbeddedResource 
= "Reportbing.rdlc";
        ReportDataSource rpt 
= new ReportDataSource("DataSet1_ShowOneFruit", ds.Tables["table2"]);

    

        newViewer.LocalReport.DataSources.Add(rpt);


        newViewer.LocalReport.Refresh();
       
        
    }

你可能感兴趣的:(view)