rdlc报表动态生成实例

rdlc报表动态生成实例_第1张图片


using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using XNCJWC.BLL;
using XNCJWC.Model;
using XNCJWC.Utility;
using Microsoft.Reporting.WebForms;
using XNCJWC.DBUtility;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

namespace XNCJWC.Web
{
    public partial class manager_StuStatus_StuBasicInfoRPT : System.Web.UI.Page
    {
        DynamicReport dr = new DynamicReport("../xncjwc/Web/manager/StuStatus/report/StuBasicInfo.rdlc");
        private DataTable dt = new DataTable();
        private StudentBLL studentbll = new StudentBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRV();
            }
        }
        private void BindRV()
        {
            string strWhere = Request.QueryString["strWhere"];
            strWhere = strWhere.Replace("|^!|", "%");
            dt = studentbll.GetStudentByWhere(strWhere);
            this.ReportViewer1.Visible = true;
            ReportDataSource reSource = new ReportDataSource("StuBasicInfo_zxsjbxx", dt);
            //ReportViewer1
            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.DataSources.Add(reSource);
            this.ReportViewer1.LocalReport.Refresh();
           
        }
        private void DynamicBindRV()
        {
            string strWhere = Request.QueryString["strWhere"];
            strWhere = strWhere.Replace("|^!|", "%");
            dt = studentbll.GetStudentByWhere(strWhere);
            this.ReportViewer1.Visible = true;
            ReportDataSource reSource = new ReportDataSource("StuBasicInfo_zxsjbxx", dt);
            ReportViewer1.Reset();
            this.ReportViewer1.LocalReport.LoadReportDefinition(GenerateRdlc());
            ReportViewer1.LocalReport.DataSources.Clear();          //Orders_DataTable1 数据源名字必须和此报表原绑定的数据源名相同
            this.ReportViewer1.LocalReport.DataSources.Add(reSource);
            this.ReportViewer1.LocalReport.Refresh();
        }
        public MemoryStream GenerateRdlc()
        {
            //dr.AddTableHaderFirstRowSingleCell("xsjbxx", "学生基本信息报表");
            if (chkxy.Checked == true)
            {
                dr.AddDetailsCell("xyd", "=Fields!fy.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("xyh", "学院");
            }
            if (chknj.Checked == true)
            {
                dr.AddDetailsCell("njd", "=Fields!nj.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("njh", "年级");
            }
            if (chkjg.Checked == true)
            {
                dr.AddDetailsCell("jgd", "=Fields!jg.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("jgh", "籍贯");
            }
            if (chkxz.Checked == true)
            {
                dr.AddDetailsCell("xzd", "=Fields!xz.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("xzh", "学制");
            }
            if (chkzy.Checked == true)
            {
                dr.AddDetailsCell("zyd", "=Fields!jw_zymc.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("zyh", "专业");
            }
            if (chkbj.Checked == true)
            {
                dr.AddDetailsCell("bjd", "=Fields!bh.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("bjh", "班级");
            }
            if (chkmz.Checked == true)
            {
                dr.AddDetailsCell("mzd", "=Fields!mz.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("mzh", "民族");
            }
            if (chkxb.Checked == true)
            {
                dr.AddDetailsCell("xbd", "=Fields!xb.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("xbh", "性别");
            }
            if (chkqq.Checked == true)
            {
                dr.AddDetailsCell("qqd", "=Fields!qq.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("qqh", "QQ");
            }
            if (chkjtzz.Checked == true)
            {
                dr.AddDetailsCell("jtzzd", "=Fields!jw_homeAddress.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("jtzzh", "家庭住址");
            }
            if (chkpycc.Checked == true)
            {
                dr.AddDetailsCell("pyccd", "=Fields!pycc.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("pycch", "培养层次");
            }
            if (chksfzh.Checked == true)
            {
                dr.AddDetailsCell("sfzhd", "=Fields!sfzh.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("sfzhh", "身份证号");
            }
            if (chkzzmm.Checked == true)
            {
                dr.AddDetailsCell("zzmmd", "=Fields!zzmm.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("zzmmh", "政治面貌");
            }
            if (chklxr.Checked == true)
            {
                dr.AddDetailsCell("lxrd", "=Fields!jw_contactMan.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("lxrh", "联系人");
            }
            if (chklxdh.Checked == true)
            {
                dr.AddDetailsCell("lxdhd", "=Fields!jw_contactNo.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("lxdhh", "联系电话");
            }
            if (chkrxrq.Checked == true)
            {
                dr.AddDetailsCell("rxrqd", "=Fields!rxrq.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("rxrqh", "入学日期");
            }
            if (chkcsrq.Checked == true)
            {
                dr.AddDetailsCell("csrqd", "=Fields!csrq.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("csrqh", "出生日期");
            }
            if (chkyzbm.Checked == true)
            {
                dr.AddDetailsCell("yzbmd", "=Fields!jw_postalCode.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("yzbmh", "邮政编码");
            }
            if (chkbz.Checked == true)
            {
                dr.AddDetailsCell("bzd", "=Fields!bz.Value");
                dr.AddTableColumn();
                dr.AddTableHeaderCell("bzh", "备注");
            }
            MemoryStream ms = new MemoryStream();
            XmlSerializer serializer = new XmlSerializer(typeof(XmlDocument));
            serializer.Serialize(ms, dr.doc);
            ms.Position = 0;
            return ms;
        }
        protected void btnPrint_Click(object sender, EventArgs e)
        {
            DynamicBindRV();
        }
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StuBasicInfoRPT.aspx.cs" Inherits="XNCJWC.Web.manager_StuStatus_StuBasicInfoRPT" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>学生基本信息报表</title>
    <style type="text/css">
        #form1
        {
            height: 636px;
            width: 1042px;
        }
        
    </style>
    <link rel="stylesheet" type="text/css" href="http://www.cnblogs.com/css/cssclass.css">
    <link rel="stylesheet" type="text/css" href="http://www.cnblogs.com/css/esv_button.css">
    <link rel="stylesheet" type="text/css" href="http://www.cnblogs.com/css/esv_master.css">
    <script src="http://www.cnblogs.com/js/common.js" type="text/JavaScript"></script>
</head>
<body>
    <form id="form1" runat="server">
  <div class="formlist">
<table width="100%">
        <tr>
         <td class="topformlist">
          <span class ="textlabel">当前位置->学籍信息管理->学籍管理->学生基本信息维护->学生基本信息报表</span>
         </td>
        </tr>   
</table>   
<table width="600">
<tr>
<td style="text-align:center" colspan="16"><span class="textlabel">请选择要打印的字段</span></td>
</tr>
<tr>
<td><asp:CheckBox ID="chkxh" runat="server" Checked="True" Enabled="False" /></td>
<td><span class="textlabel">学号</span></td>
<td><asp:CheckBox ID="chkxm" runat="server" Checked="True" Enabled="False" /></td>
<td><span class="textlabel">姓名</span></td>
<td><asp:CheckBox ID="chkxy" runat="server" /></td>
<td><span class="textlabel">学院</span></td>
<td><asp:CheckBox ID="chknj" runat="server" /></td>
<td><span class="textlabel">年级</span></td>

<td><asp:CheckBox ID="chkjtzz" runat="server"/></td>
<td><span class="textlabel">家庭住址</span></td>
<td><asp:CheckBox ID="chkpycc" runat="server"  /></td>
<td><span class="textlabel">培养层次</span></td>

<td><asp:CheckBox ID="chkrxrq" runat="server"/></td>
<td><span class="textlabel">入学日期</span></td>
<td style="width: 10px"> </td>
<td style="width: 10px"> </td>
</tr>
<tr>
<td><asp:CheckBox ID="chkjg" runat="server"  /></td>
<td><span class="textlabel">籍贯</span></td>
<td><asp:CheckBox ID="chkxz" runat="server" /></td>
<td><span class="textlabel">学制</span></td>
<td><asp:CheckBox ID="chkzy" runat="server" /></td>
<td><span class="textlabel">专业</span></td>
<td><asp:CheckBox ID="chkbj" runat="server" /></td>
<td><span class="textlabel">班级</span></td>
<td><asp:CheckBox ID="chksfzh" runat="server"  /></td>
<td><span class="textlabel">身份证号</span></td>
<td><asp:CheckBox ID="chkzzmm" runat="server"/></td>
<td><span class="textlabel">政治面貌</span></td>
<td><asp:CheckBox ID="chkcsrq" runat="server"/></td>
<td><span class="textlabel">出生日期</span></td>
<td style="width: 10px"> </td>
<td style="width: 10px"> </td>
</tr>
<tr>
<td><asp:CheckBox ID="chkmz" runat="server" /></td>
<td><span class="textlabel">民族</span></td>
<td><asp:CheckBox ID="chkxb" runat="server"/></td>
<td><span class="textlabel">性别</span></td>
<td><asp:CheckBox ID="chkqq" runat="server"  /></td>
<td><span class="textlabel">QQ</span></td>
<td><asp:CheckBox ID="chkbz" runat="server"  /></td>
<td><span class="textlabel">备注</span></td>
<td><asp:CheckBox ID="chklxr" runat="server"/></td>
<td><span class="textlabel">联系人</span></td>
<td><asp:CheckBox ID="chklxdh" runat="server" /></td>
<td><span class="textlabel">联系电话</span></td>
<td><asp:CheckBox ID="chkyzbm" runat="server"  /></td>
<td><span class="textlabel">邮政编码</span></td>
<td align ="right" width="90"><asp:Button ID="btnPrint" runat="server" 
        class="bt_print" CssClass="bt_print" 
                           Text="  确定" onclick="btnPrint_Click" />
</td>
<td style="width: 10px"> </td>
</tr>
</table>
     <div style="overflow-y: scroll; height: 800px; width:600" id="dvBody"> 
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" Height="600px" Width="800px">
        <LocalReport ReportPath="manager\StuStatus\report\StuBasicInfo.rdlc">
        </LocalReport>
    </rsweb:ReportViewer>   
        
    </div>       
</div>
    </form>
</body>
</html>



你可能感兴趣的:(实例)