c#.net报告服务为.rdlc报告动态创建可选页脚

时间:2022-10-19 08:09:06

I already searched for this and I did not find the answer I was looking for.

我已经搜索了这个,但我找不到我想要的答案。

I am writing a windows forms program with C# .NET and Visual Studio 2008. I am using Reporting Services and rendering the reports using the .net provided report viewer. The data source for the reports is SQL Server. I am rendering the reports locally. I am not using a report server. The reports are .rdlc files.

我正在使用C#.NET和Visual Studio 2008编写Windows窗体程序。我正在使用Reporting Services并使用.net提供的报表查看器呈现报表。报告的数据源是SQL Server。我在本地渲染报告。我没有使用报表服务器。报告是.rdlc文件。

I would like to programmatically add a page footer to the report (not a table footer) based on input from the user in a form. I do know how to pass parameters to a report from a windows form. I don't know how to use this technique or another technique to dynamically create or remove a footer. When the footer is created on the fly I need to add text.

我想以编程方式根据表单中用户的输入将页脚添加到报表(而不是表格页脚)。我知道如何从Windows窗体传递参数到报表。我不知道如何使用此技术或其他技术来动态创建或删除页脚。在动态创建页脚时,我需要添加文本。

Currently I have a permanent footer with text boxes that I populate by passing parameters to the report viewer.

目前我有一个带有文本框的永久页脚,我通过将参数传递给报表查看器来填充。

List<ReportParameter> parameters = new List<ReportParameter>();

parameters.Add(new ReportParameter("FootnoteLine1", FootnoteLine1.ToString()));

parameters.Add(new ReportParameter("FootnoteLine2", FootnoteLine2.ToString()));

reportViewer1.LocalReport.SetParameters(parameters);

Any help is appreciated.

任何帮助表示赞赏。

2 个解决方案

#1


You are going to have to learn to use VB.NET in order to use the Custom Code feature of Reporting Services. Another option is to write an expression that returns false when the user does not enter a valid parameter, and a true when the user has entered a valid parameter. This expression should be set for the "Hide/Show" field of the footer. This field should be found in the footer or text box "Properties" dialogue.

您将不得不学习使用VB.NET以使用Reporting Services的自定义代码功能。另一种选择是编写一个表达式,当用户没有输入有效参数时返回false,当用户输入有效参数时返回true。应为页脚的“隐藏/显示”字段设置此表达式。该字段应在页脚或文本框“属性”对话框中找到。

#2


The only way I was able to achieve the level of flexibility I wanted at runtime was to write code to build the .rdlc file from scratch. The rdlc files are just XML, which means the .net xml classes can be used to generate the file. If the user does not want a footer, then the program simply does not write that part of the xml file.

我能够在运行时获得我想要的灵活性的唯一方法是编写代码以从头开始构建.rdlc文件。 rdlc文件只是XML,这意味着.net xml类可用于生成文件。如果用户不想要页脚,则程序根本不会写入xml文件的那一部分。

MSDN even has a tutorial on how to do this.

MSDN甚至有一个如何做到这一点的教程。

http://msdn.microsoft.com/en-us/library/ms170239.aspx

#1


You are going to have to learn to use VB.NET in order to use the Custom Code feature of Reporting Services. Another option is to write an expression that returns false when the user does not enter a valid parameter, and a true when the user has entered a valid parameter. This expression should be set for the "Hide/Show" field of the footer. This field should be found in the footer or text box "Properties" dialogue.

您将不得不学习使用VB.NET以使用Reporting Services的自定义代码功能。另一种选择是编写一个表达式,当用户没有输入有效参数时返回false,当用户输入有效参数时返回true。应为页脚的“隐藏/显示”字段设置此表达式。该字段应在页脚或文本框“属性”对话框中找到。

#2


The only way I was able to achieve the level of flexibility I wanted at runtime was to write code to build the .rdlc file from scratch. The rdlc files are just XML, which means the .net xml classes can be used to generate the file. If the user does not want a footer, then the program simply does not write that part of the xml file.

我能够在运行时获得我想要的灵活性的唯一方法是编写代码以从头开始构建.rdlc文件。 rdlc文件只是XML,这意味着.net xml类可用于生成文件。如果用户不想要页脚,则程序根本不会写入xml文件的那一部分。

MSDN even has a tutorial on how to do this.

MSDN甚至有一个如何做到这一点的教程。

http://msdn.microsoft.com/en-us/library/ms170239.aspx