需求:在view视图页面中嵌入rdlc报表,rdlc的xml为动态传入的xml字符串。本项目是基于abp框架

可能出现问题:

1、rdlc报表是由asp.net的服务器控件ReportViewer来支持的,view视图不能直接使用服务器控件

2、ReportViewer需要通过aspx页面来承载,并在服务端事件中完成对控件的xml绑定、datatable绑定

3、由于是基于abp框架的项目,不能在aspx.cs后台页面中直接实例化IxxAppService接口的实现类


想达到的效果如下图:

上部分为报表的筛选区域,下部分为rdlc报表展示内容。


本次实现的思路为:

1、以view视图为主页面,在视图的上部分完成筛选信息的展示和绑定;

2、视图下部分嵌入一个iframe,iframe地址指向一个aspx页面,该页中实现ReportViewer控件的赋值和绑定

视图页面的代码参考如下:

    <div class="tab-content" style="width:100%;height:100%">
<!--筛选区域-->
<div role="tabpanel" class="tab-pane active" id="navMenu" style="padding-top: 4px;padding-bottom: 1px;"> <div class="collapse row" id="filterHts" style="margin-right: 2px;">
</div>
<div id="divTools" style="padding: 0 5px 5px;cursor: pointer;height: 33px;line-height:28px" title="点击展开搜索条件区">
<span id="searchTools" onclick="$('#filterHts').click();" style="display:none;float:left"></span>
<span id="ExternalTools" style="float:left;"></span>
<span id="spTools" style="float:left;"></span>
<span id="spanSearch" style="float:right;line-height:12px;height:12px"><i class="fa fa-chevron-down" title="点击展开搜索条件区" aria-hidden="true" style="cursor:pointer;margin:0px 0px 0px 5px;color:#76838f"></i><i class="fa fa-chevron-up" aria-hidden="true" title="点击关闭搜索条件区" style="cursor:pointer;display:none;margin-left:5px;color:#76838f"></i></span>
</div> </div>
<div style="width:100%;height:500px">
<iframe style="width:100%;height:500px" id="ifm" src="~/Rdlc/rdlc.aspx"></iframe>
</div>
</div>

rdlc.aspx页面代码参考:

<%@ Page Language="C#" CodeBehind="rdlc.aspx.cs" Inherits="Easyman.Web.Rdlc.rdlc" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField runat="server" ID="rpName" />
<asp:HiddenField runat="server" ID="xmlStr" />
<asp:HiddenField runat="server" ID="hidDataTable" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="reportViewer1" runat="server" DocumentMapWidth="100%" Font-Names="Verdana"
Font-Size="8pt" WaitMessageFont-Names="Verdana" AsyncRendering="False" SizeToReportContent="True"
WaitMessageFont-Size="14pt" Width="100%" Height="100%" ZoomMode="FullPage" >
</rsweb:ReportViewer>
</div>
<div style="display:none">
<asp:Button ID="SearchBtn" runat="server" OnClick="SearchBtn_Click" Text="查询" />
</div>
</form>
</body>
</html>

当点击了视图页查询按钮之后,在视图页中实现对 rdlc.aspx页面中的隐藏控件赋值(aspx页面中隐藏控件有:xml、datatable的json数据)

隐藏控件赋值之后触发 rdlc.aspx页面查询按钮事件SearchBtn_Click

视图页关键js如下:

        $("#ifm").contents().find("#rpName").val($("#Name").val());
$("#ifm").contents().find("#xmlStr").val(Encrypt(rdlcReport.RdlcXml));
$("#ifm").contents().find("#hidDataTable").val(data.responseText); //endregion $("#ifm").contents().find("#SearchBtn").click();//触发RDLC子页面的查询按钮
$("#ifm").contents().find("#SearchBtn").hide();

rdlc.aspx.cs查询后台事件方法SearchBtn_Click的代码如下:

        protected void SearchBtn_Click(object sender, EventArgs e)
{
string xmlStr = EncryptHelper.AesDecrpt(this.xmlStr.Value);
string tbJson = this.hidDataTable.Value;
string rpName = this.rpName.Value;
DataTable dt = new DataTable();
if(!string.IsNullOrEmpty( tbJson)&&tbJson!="[]")
{
dt = JSON.ToDataTable(tbJson);
}
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DisplayName = rpName;
reportViewer1.LocalReport.LoadReportDefinition(GenerateRdlc(xmlStr));
ReportDataSource reportDataSource = new ReportDataSource("DataSet1",dt);
reportViewer1.LocalReport.DataSources.Add(reportDataSource);
reportViewer1.LocalReport.Refresh(); }

rdlc.aspx.cs后台的完整代码如下:

using Abp.Domain.Repositories;
using Easyman.Common;
using Easyman.Common.Helper;
using Easyman.Domain;
using Easyman.Service;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace Easyman.Web.Rdlc
{
public partial class rdlc : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 以内存流形式返回rdlc报表配置信息
/// </summary>
/// <param name="inStr"></param>
/// <returns></returns>
public MemoryStream GenerateRdlc(string inStr)
{
byte[] b = Encoding.UTF8.GetBytes(inStr);
MemoryStream ms = new MemoryStream(b);
return ms;
}
protected void SearchBtn_Click(object sender, EventArgs e)
{
string xmlStr = EncryptHelper.AesDecrpt(this.xmlStr.Value);
string tbJson = this.hidDataTable.Value;
string rpName = this.rpName.Value;
DataTable dt = new DataTable();
if(!string.IsNullOrEmpty( tbJson)&&tbJson!="[]")
{
dt = JSON.ToDataTable(tbJson);
}
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DisplayName = rpName;
reportViewer1.LocalReport.LoadReportDefinition(GenerateRdlc(xmlStr));
ReportDataSource reportDataSource = new ReportDataSource("DataSet1",dt);
reportViewer1.LocalReport.DataSources.Add(reportDataSource);
reportViewer1.LocalReport.Refresh(); }
}
}

总体思路为:

1)在view视图页中实现筛选区域的值绑定和获取;

2)并在筛选条件下查询满足的datatable数据并转化为json字符串赋值给子页面rdlc.aspx的隐藏控件;

3)在view视图中给子页面rdlc.aspx隐藏控件xml配置信息赋值

4)在rdlc.aspx子页面的后台事件方法SearchBtn_Click中直接获取隐藏控件中的datatable数据和rdlc的配置xml字符串信息,然后绑定到ReportViewer控件


以上是最早期的实现,以下地址为后期调整补充:

在mvc视图中实现rdlc报表展示(补充)

在mvc视图中实现rdlc报表展示的更多相关文章

  1. 在mvc视图中实现rdlc报表展示(补充)

    上篇: 在mvc视图中实现rdlc报表展示 在上一遍中,由于不知道如何在aspx.cs后台中实例化abp的IxxxAppService.cs的接口,我采取的方式是在视图页中把查询出的数据存储到aspx ...

  2. 基于MVC4+EasyUI的Web开发框架经验总结(15)--在MVC项目中使用RDLC报表

    RDLC是一个不错的报表,有着比较不错的设计模式和展现效果,在我的Winform开发里面,使用RDLC也是一个比较方便操作,如可以参考文章<DevExpress的XtraReport和微软RDL ...

  3. 在MVC项目中使用RDLC报表

    原文地址:http://www.cnblogs.com/wuhuacong/p/4109833.html RDLC是一个不错的报表,有着比较不错的设计模式和展现效果,在我的Winform开发里面,使用 ...

  4. MVC视图中的@Html.xxx(...)

    ASP.NET MVC视图中的@Html.xxx(...)   问题 在视图页中@Html.xxx(...)是什么?如何被执行? 如下图所示: 解疑 视图页中@Html.xxx(...)涉及的内容有: ...

  5. VSTO 学习笔记(六)在 Excel 2010中使用RDLC报表

    原文:VSTO 学习笔记(六)在 Excel 2010中使用RDLC报表 Excel具有强大的图表显示.分析功能,这点毋庸置疑,但是如果将常规MIS系统中的数据以报表的形式在Excel中显示,却并不那 ...

  6. 项目中使用RDLC报表

    原文地址:http://www.cnblogs.com/wuhuacong/p/4109833.html RDLC是一个不错的报表,有着比较不错的设计模式和展现效果,在我的Winform开发里面,使用 ...

  7. MVC视图中Html.DropDownList()辅助方法的使用

    我们先在控制器中准备好一个SelectList类型,然后通过ViewBag.List传入视图中.SelectList类型是ASP.NET MVC专门为列表有关的HTML辅助方法提供选项的,例如,Htm ...

  8. asp.net mvc视图中使用entitySet类型数据时提示出错

    asp.net mvc5视图中使用entitySet类型数据时提示以下错误 检查了一下引用,发现已经引用了System.Data.Linq了,可是还是一直提示出错, 后来发现还需要在Views文件夹下 ...

  9. 解决.NET Core MVC 视图中的中文被html编码的问题

    在  .net core mvc 视图输出 变量的时候 默认使用的是 UnicodeRanges.BasicLatin  进行的编码 所以 输出中文后在查看源码的时候是进过编码了的 . 解决方案 在 ...

随机推荐

  1. 鼠标悬浮控制元素隐藏与显示 - css中鼠标的hover状态

    需求:当鼠标移动到一个元素A身上时,另外一个元素B显示. 实现原理: A元素与B元素有一个相同的父级. B元素默认隐藏,A元素默认显示. 当鼠标移动到A元素身上时,也可以看做是移动到了A元素的父级身上 ...

  2. flex 总结

  3. T-SQL的timestamp类型实际应用

    目录 0x00 适用场景 0x01 问题描述 0x02 字节数组 0x03 Base64编码 0x04 其实没那么麻烦 0x05 回顾 0x00 适用场景 1. 前端: JavaScript 2. 后 ...

  4. Python笔记(九):字符串操作

    (一)    字符串 单引号.双引号.三重引号都可以作为字符串的开始和结束,三重引号可以直接输入多行字符串.三重引号可能一般是用来写多行注释. (二)    r和\ r使字符串成为原始字符串,忽略所有 ...

  5. CSS 小结笔记之变形、过渡与动画

    1.过渡 transition  过渡属性用法: transition :ransition-property  transition-duration  transition-timing-func ...

  6. Linux Ubuntu16.04LTS安装TensorFlow(CPU-only,python3.7)——使用Anaconda安装

    1.安装Anaconda(在此不再赘述) 2.用Conda安装TensorFlow 1)建立TensorFlow运行环境并激活 conda create -n tensorflow pip pytho ...

  7. HttpWebRequest 禁用系统默认代理

    方法一 将HttpWebRequest对象的Proxy属性设置为null 方法二 配置文件修改 <proxy usesystemdefault="False" />

  8. Node.js+Ajax实现物流小工具

    半年过去了,好像什么也没干,好像什么也干了. 最近在网易云课堂上看到了这个课程,觉得很有意思,就跟着课程做了一遍,课程地址:http://study.163.com/course/courseMain ...

  9. Linux基础知识与基础命令

    Linux基础知识与基础命令 系统目录 Linux只有一个根目录,没有盘符的概念,文件目录是一个倒立的树形结构. 常用的目录功能 bin 与程序相关的文件 boot 与系统启动相关 cdrom 与Li ...

  10. django —— 邮件

    官方文档 1.11 配置settings.py # QQ邮箱为例, 其他邮箱对应的SMTP配置可查官方 EMAIL_HOST = "smtp.qq.com" EMAIL_PORT ...