rdlc报表实质上是一个xml文件,如果要实现动态报表,就需要动态生成rdlc文件,实质上就是读写xml文件:

  protected XmlDocument GenerationAddReportColumn(IList<ReportColumn> columnList,
string fromRdlcPath, string toRdlcPath)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath(fromRdlcPath)); XmlNodeList fileds = xmlDoc.GetElementsByTagName("Fields");
XmlNodeList tablixColumns = xmlDoc.GetElementsByTagName("TablixColumns");
XmlNodeList tablixMembers = xmlDoc.GetElementsByTagName("TablixColumnHierarchy");
XmlNodeList tablixRows = xmlDoc.GetElementsByTagName("TablixRows"); foreach (var item in columnList)
{
//添加Field节点
XmlNode filedNode = fileds.Item().FirstChild.CloneNode(true);
if (!fileds.Item().ChildNodes.Cast<XmlNode>().Any(c=>c.Attributes["Name"].Value==item.Field))
{
filedNode.Attributes["Name"].Value = item.Field;
filedNode.FirstChild.InnerText = item.Field;
filedNode.ChildNodes[].InnerText = string.IsNullOrWhiteSpace(item.FieldType) ? "System.String" : item.FieldType;
fileds.Item().AppendChild(filedNode);
} //添加TablixColumn
XmlNode tablixColumn = tablixColumns.Item().FirstChild;
XmlNode newtablixColumn = tablixColumn.CloneNode(true);
newtablixColumn.FirstChild.InnerText = item.Width;
tablixColumns.Item().AppendChild(newtablixColumn); //TablixMember
XmlNode tablixMember = tablixMembers.Item().FirstChild.FirstChild;
XmlNode newTablixMember = tablixMember.CloneNode(true);
tablixMembers.Item().FirstChild.AppendChild(newTablixMember); var tablixRowsRowCells1 = tablixRows.Item().FirstChild.ChildNodes[];
XmlNode tablixRowCell1 = tablixRowsRowCells1.FirstChild;
XmlNode newtablixRowCell1 = tablixRowCell1.CloneNode(true);
var textBox1 = newtablixRowCell1.FirstChild.ChildNodes[];
textBox1.Attributes["Name"].Value = "Textbox_"+item.Field; var paragraphs = textBox1.ChildNodes.Cast<XmlNode>().Where(c => c.Name == "Paragraphs").FirstOrDefault();
paragraphs.FirstChild.FirstChild.FirstChild.FirstChild.InnerText = item.ColumnName;
var defaultName1 = textBox1.ChildNodes.Cast<XmlNode>().Where(c => c.Name == "rd:DefaultName").FirstOrDefault().InnerText = "Textbox_" + item.Field; tablixRowsRowCells1.AppendChild(newtablixRowCell1); var tablixRowsRowCells2 = tablixRows.Item().ChildNodes[].ChildNodes[];
XmlNode tablixRowCell2 = tablixRowsRowCells2.FirstChild;
XmlNode newtablixRowCell2 = tablixRowCell2.CloneNode(true);
var textBox2 = newtablixRowCell2.FirstChild.ChildNodes[];
textBox2.Attributes["Name"].Value = item.Field; var paragraphs2 = textBox2.ChildNodes.Cast<XmlNode>().Where(c => c.Name == "Paragraphs").FirstOrDefault();
paragraphs2.FirstChild.FirstChild.FirstChild.FirstChild.InnerText = "=Fields!" + item.Field + ".Value";
var defaultName2 = textBox2.ChildNodes.Cast<XmlNode>().Where(c => c.Name == "rd:DefaultName").FirstOrDefault().InnerText = item.Field; tablixRowsRowCells2.AppendChild(newtablixRowCell2); } xmlDoc.Save(Server.MapPath(toRdlcPath));
return xmlDoc; }
    /// <summary>
/// 报表列描述
/// </summary>
public class ReportColumn
{
public string Field { get; set; } public string ColumnName { get; set; } public string Width { get; set; } public string FieldType { get; set; }
}

最新文章

  1. IaaS、PaaS、SaaS 之间的区别
  2. 【译】About the Java Technology
  3. linux mount 硬盘挂载和卸载
  4. 19.fastDFS集群理解+搭建笔记
  5. DLL分类
  6. Asp.Net MVC 路由
  7. Silverlight 读取配置文件
  8. Cocos2d-android (02) 添加一个精灵对象
  9. Mysql 分页语句Limit用法
  10. MyEclipse server窗口 Could not create the view: An unexpected exception was thrown 错误解决
  11. Activity被回收导致fragment的getActivity为null的解决办法
  12. MySQL基础----动态SQL语句
  13. JavaWeb开发环境搭建Eclipse配置Tomcat
  14. 什么是Zookeeper?
  15. 正态分布-python建模
  16. Net中应用 Redis 扩展类
  17. pycharm 的操作1
  18. 模拟界面请求到web服务器
  19. js比较两个String字符串找出不同,并将不同处高亮显示
  20. Asm 常用资源

热门文章

  1. Xamarin图表开发基础教程(1)
  2. flutter PopupMenuButton弹出式菜单列表
  3. pytorch 计算图像数据集的均值和标准差
  4. Laya的资源加载
  5. 报错:(未解决)Opening socket connection to server master/192.168.52.26:2181. Will not attempt to authenticate using SASL (unknown error)
  6. PngOptimizer PNG压缩工具
  7. Docker:学习笔记(1)——基础概念
  8. robot:List变量的使用注意点
  9. 干货 | 20多门AI网络课程资源(附链接+PDF)
  10. php面向对象(文件操作)