您的位置:首页 > 编程语言 > C#

C#子报表功能

2016-02-22 11:36 507 查看
调用的是reportViewer1.LocalReport.SubreportProcessing

下面是实现步骤

1.主RepMain.rdlc配置

2.子RepMainChild.rdlc配置

3,主窗体绑定RepMain.rdlc,代码如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace 钻取子报表
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.LoadReport();
}
private void button1_Click(object sender, EventArgs e)
{
this.LoadReport();
}

protected void LoadReport()
{
string depid = this.textBox1.Text.Trim().ToString();
string sql = @"select depid,depname,parents from dep where 1=1";
if (depid.Length>0)
{
sql += " and depid='" + depid + "'";
}
DataTable dt = DBUtil.getDataTable(sql);

ReportDataSource rds = new ReportDataSource("DataSet1", dt);

this.reportViewer1.LocalReport.SubreportProcessing += LocalReport_SubreportProcessing;

this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(rds);

this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
}

void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{

string depid = this.textBox1.Text.Trim().ToString();
string sql = @"select userid,username,depid from users where 1=1";
if (depid.Length > 0)
{
sql += " and depid='" + depid + "'";
}
DataTable dt = DBUtil.getDataTable(sql);

ReportDataSource rds = new ReportDataSource("DataSet1", dt);

e.DataSources.Clear();
e.DataSources.Add(rds);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: