现在的位置: 首页 > 综合 > 正文

ReportViewer动态加载报表文件

2012年02月01日 ⁄ 综合 ⁄ 共 1540字 ⁄ 字号 评论关闭
/*页面上放置一个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();
       
        
    }

抱歉!评论已关闭.