ReportViewer的动态绑定

 

aspx页面关键代码 代码

复制代码
<body>
  
    
<form id="form1" runat="server">
     
<asp:ScriptManager ID="ScriptManager1" runat="server">
    
</asp:ScriptManager>
    
     
<uc2:StatementQuery ID="StatementQuery1" runat="server" />
     
     
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="View Report" />
            
<asp:Button
                
ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
            
<asp:TextBox ID="txtParameter" runat="server"></asp:TextBox>
    
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
                
>
                
<LocalReport ReportPath="statement/Report_Metal.rdlc" >
                    
<DataSources>
                        
<rsweb:ReportDataSource />
                    
</DataSources>
                
</LocalReport>
            
</rsweb:ReportViewer> 
        


    
</form>
  
    
</body>
复制代码

 

C#关键代码

复制代码
代码
 private void BindReportViewer()
        {






            BusinessLogic.MetalStatViewCollection MSVCOLL = new BusinessLogic.MetalStatViewCollection();
            MSVCOLL = BusinessLogic.MetalStatViewCollection.getMetalStatViewCollection("year=2009 and month=12 and day=3");
            IList<rMSV> MSVList = new List<rMSV>();
            
foreach (MetalStatView m in MSVCOLL)
            {
                MSVList.Add(new rMSV(m.GroupField, m.clientName, m.weight, m.amount));
            }




            ReportDataSource rds = new ReportDataSource("DataSet_Metal_DataTableMetal", MSVList);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh();
        }
复制代码

 

 

需要用dataset的XSD文件作为中转。

详细过程,可以参考:http://www.codeproject.com/kb/aspnet/ReportViewer.aspx 

 

 以前按照MSDN的指导,有成功使用过动态绑定RDLC,可这次使用到业务对象,并用ObjectDataSource来作为数据源的中转,结果搞了几天,也总是有问题。

后来,重头来过,不用ObjectDataSource,按codeproject上的简单例子,实现了动态绑定,再将我们要使用的业务对象加上去,通过XSD来中转,一样完成了目标功能。

http://four-corner.appspot.com/

 

 

http://anforen.5d6d.com/ 

posted on   公众号73只蚂蚁  阅读(3749)  评论(0编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述

导航

< 2010年4月 >
28 29 30 31 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示