各位大侠,如何后台控制rdlc报表中子报表的数量,可不可以通过后台代码向rdlc报表中动态添加SubReport,并且为其指定子报表?

解决方案 »

  1.   

    这个已经解决了,不过实现起来代码还是很多的,如下方案仅供参考,如果哪位大侠还有更好的办法可以告诉我滴,谢谢各位
    主要是修改RDLC主报表中子报表的名称,从而实现一种动态加载子报表的功能,首先加载RDLC文件到XmlDocument中,找到SubReport节点,对其子报表名称进行修改:(部分代码如下)
    ModifyAnySubreport(listsubreportname, rdlcReportPath);
                 //加载主报表
                    DefineMainReport(rdlcReportPath);
                 //加载子报表
                    foreach (string s in listsubreportname)
                 {
                    string subReportPath = @"E:\学习的东西(程序)\WinForm中都有哪些可用报表\RDLC\RDLCPrint\RDLCPrint\Reports\" + s + ".rdlc";
                    StreamReader subReport = new StreamReader(subReportPath);
                    this.reportViewer1.LocalReport.LoadSubreportDefinition(s, subReport);
                 }             this.reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessingNKWKAndYK);
                 this.reportViewer1.RefreshReport();void ModifyAnySubreport(List<string> listsubreportname, string rdlcReprotPath)
    {
         int i = 0;
         XmlDocument doc = new XmlDocument();
         doc.Load(rdlcReprotPath);     XmlNodeList element = doc.GetElementsByTagName("Subreport");
         foreach (XmlNode node in element)
         {
             XmlNode n = (XmlNode)node.ChildNodes[1];
             n.InnerText = listsubreportname[i].ToString();
             i++;
         }
         doc.Save(rdlcReprotPath);
     }