RDLC-ReportView控件动态绑定报表和数据源
2009-04-18 23:31
447 查看
通过ReportView设计界面可以很方便的设置需要绑定的报表文件(rdlc文件)和数据源,但在有时需要根据用户操作通过后台程序动态绑定设计好的rdlc报表和数据源。接下来看看如何方便的实现。。
//动态绑定报表
private void BindDataTable(string rdlcstr,string tablename,string sourcename,DataTable dt)
{
Common_RV.Reset();
Common_RV.LocalReport.ReportEmbeddedResource = rdlcstr;
ReportDataSource datasouce = new ReportDataSource();
BindingSource bind = new BindingSource(this.components);
//过滤排序
dt.DefaultView.RowFilter="";
//dt.DefaultView.Sort = "";
bind.DataMember = tablename;
bind.DataSource = dt.DefaultView;
datasouce.Name = sourcename;
datasouce.Value = bind;
Common_RV.LocalReport.DataSources.Clear();
Common_RV.LocalReport.DataSources.Add(datasouce);
Common_RV.RefreshReport();
}
1、使用方式:
BindDataTable("ReportTest.CCDetailReport.rdlc","CCDetailTable","ReportDataSet_CCDetailTable",ReportDataSet.CCDetailTable);
2、参数说明:
rdlcstr:报表文件名,要加命名空间的
tablename:dataset总的table名
sourcename:这个比较奇怪,我也没搞清楚为什么一定要这么写,只是在它的design文件中是这么做的,格式是:dataset实例名+_+table名称
dt:table实例,这里传table过来主要是要使用table的defaultview,可以实现报表的过滤和排序,如果不考虑这些,bind.DataSource可以直接设置成dataset实例就可以了
//动态绑定报表
private void BindDataTable(string rdlcstr,string tablename,string sourcename,DataTable dt)
{
Common_RV.Reset();
Common_RV.LocalReport.ReportEmbeddedResource = rdlcstr;
ReportDataSource datasouce = new ReportDataSource();
BindingSource bind = new BindingSource(this.components);
//过滤排序
dt.DefaultView.RowFilter="";
//dt.DefaultView.Sort = "";
bind.DataMember = tablename;
bind.DataSource = dt.DefaultView;
datasouce.Name = sourcename;
datasouce.Value = bind;
Common_RV.LocalReport.DataSources.Clear();
Common_RV.LocalReport.DataSources.Add(datasouce);
Common_RV.RefreshReport();
}
1、使用方式:
BindDataTable("ReportTest.CCDetailReport.rdlc","CCDetailTable","ReportDataSet_CCDetailTable",ReportDataSet.CCDetailTable);
2、参数说明:
rdlcstr:报表文件名,要加命名空间的
tablename:dataset总的table名
sourcename:这个比较奇怪,我也没搞清楚为什么一定要这么写,只是在它的design文件中是这么做的,格式是:dataset实例名+_+table名称
dt:table实例,这里传table过来主要是要使用table的defaultview,可以实现报表的过滤和排序,如果不考虑这些,bind.DataSource可以直接设置成dataset实例就可以了
相关文章推荐
- 在Silverlight中动态绑定页面报表(PageReport)的数据源
- 在Silverlight中动态绑定页面报表(PageReport)的数据源
- reportviewer 控件动态绑定数据 报表灵活绑定数据
- asp.net中轻量级报表RDLC的动态数据绑定
- ReportView报表实现带参数存储过程创建报表以及为rdlc传递参数
- 动态绑定数据源的ReportViewer终于搞定了
- RDLC报表系列(一) 简单的动态数据绑定和配置
- DropdownList控件动态绑定数据源两…
- 真正的全动态报表:RDLC+ReportViewer
- 使用ActiveReport for .net 进行报表开发(二)--绑定数据源 (转)
- asp.net中ListView控件动态绑定数据源后,使用DataPager出现错误的原因及解决办法
- ReportView报表实现带参数存储过程创建报表以及为rdlc传递参
- 用ReportView控件展示Rdl服务器报表可行性研究
- VS2005下水晶报表如何实现动态数据源绑定?
- 使用ActiveReport for .net 进行报表开发(二)--绑定数据源
- RDLC(REPORT VIEW)导出PDF报表中文乱码问题
- [转]VS2005下水晶报表实现动态数据源绑定
- VS2005下水晶报表如何实现动态数据源绑定
- 动态绑定数据源的ReportViewer终于搞定了
- vs2010 rdlc报表一:绑定list数据源