需求:在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. vue.js关于路由的跳转

    1.路由demo示例 <div id="app"> <h1>Hello App!</h1> <p> <!-- 使用 route ...

  2. 通过ssh实现远程登陆服务器!

    通过ssh实现远程登陆前提是服务器已经开启ssh服务,至于怎么开启,可以参看上一篇“Linux服务器开启ssh服务,实现ssh远程登陆!”! 使用ssh登陆时,输入主机(linux的ip地址),账号, ...

  3. JavaScript小细节点罗列(2)

    break 语句和 continue 语句 break语句和continue语句都具有跳转作用,可以让代码不按既有的顺序执行. break语句用于跳出代码块或循环. var i = 0; while( ...

  4. Android 限定符

    Android中一些常见的限定符可以参考下表. 使用最小宽度限定符 在上一小节中我们使用large限定符成功解决了单页双页的判断问题,不过很快又有一个新的问题出现了,large到底是指多大呢?有的时候 ...

  5. Android--监听View的两个指头是放大和缩小

    private double nLenStart = 0;//监听 WebView所用手势 @Override public boolean onTouch(View v, MotionEvent e ...

  6. Java语言的特点以及Java与C/C++的异同

    Java语言的特点 1. Java为纯面向对象的语言,能够直接反应现实生活中的对象,容易理解,编程更容易. 2.跨平台,java是解释性语言,编译器会把java代码变成中间代码,然后在JVM上解释执行 ...

  7. react native进阶

    一.前沿||潜心修心,学无止尽.生活如此,coding亦然.本人鸟窝,一只正在求职的鸟.联系我可以直接微信:jkxx123321 二.项目总结 **||**文章参考资料:1.  http://blog ...

  8. shell 的echo和 printf

    shell的echo指令是输出语句  就好比Python的print 在显示字符串的时候可以省略双引号  但是最好还是带上 echo ' Ti is a dashaobing' echo Ti is ...

  9. 自动代码质量分析(GitLab+JenKins+SonarQube)

    自动代码质量分析(GitLab+JenKins+SonarQube) 1.需求场景 开发提交代码自动执行代码质量分析. 2.所需应用 GitLab,JenKins,SonarQube 3.架构图 4. ...

  10. 【转】Linux思维导图

    [原文]https://www.toutiao.com/i6591690511763898888/ 1.Linux学习路径: 2.Linux桌面介绍: 3.FHS(文件系统目录标准): 4.Linux ...