需求:在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. lamp配置多个虚拟站点

    在同一ip下添加多个域名站点! 1.查看ip 命令:ifconfig 2.添加域名 命令:vi /etc/hosts 输入域名:如 192.168.160.127   www.test.com 192 ...

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

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

  3. [经典bug]弹框关闭按钮点击后程序闪退

    问题背景: 业务上遇到一个很诡异的问题:弹框界面上有一个关闭按钮,切换后台再返回后,点击关闭按钮,部分机型上会直接崩溃.点击手机返回键关闭界面则正常. 问题原因: 点击关闭按钮的操作属于UI线程,直接 ...

  4. Oracle EBS 创建 RMA

    DECLARE l_api_version_number NUMBER := 1; l_return_status VARCHAR2(2000); l_msg_count NUMBER; l_msg_ ...

  5. innodb_fast_shutdown的内幕

    Innodb_fast_shutdown告诉innodb在它关闭的时候该做什么工作.有三个值可以选择:1.  0表示在innodb关闭的时候,需要purge all, merge insert buf ...

  6. wc 命令使用说明

    wc 命令 使用说明 wc 命令还是很是简单的,通过 man 命令,可以见到可以选择的选项: wc option file 并且 wc 命令支持 管道操作 其中较为常用的命令选项 -c 字符的个数 - ...

  7. python字典的基本操作

    字典的基本方法 什么是字典: 字典是一种 key - value的数据类型,听alex说就像我们上学用的字典,通过笔划,字母来查找对饮页面的详细内容. 语法: id_dict = { 'stu1101 ...

  8. 从PFX文件中获取私钥、公钥证书、公钥

    https://blog.csdn.net/ZuoYanYouYan/article/details/77868584 该类具体功能:根据pfx证书得到私钥.根据私钥字节数组获取私钥对象.根据公钥字节 ...

  9. ReportViewer 安装

    选择“工具”>“Nuget包管理器”>“程序包管理器控制台” 执行命令:Install-Package Microsoft.ReportingServices.ReportViewerCo ...

  10. time模块案例演示

    案例01: 2008年8月8日20:08:08 往后88,888,888秒是哪天?星期几? 日期->时间戳(浮点数)->可以做数学运算 演示: import time # 构造日期的元组, ...