我如何在rdlc报告中使用局部参数

问题描述

我想在rdlc报告中使用变量名ReportTitle的值

我的C#代码是:

this.Report1.LocalReport.ReportPath = @"Report1.rdlc";
ReportParameterCollection reportParms1 = new ReportParameterCollection();
reportParms1.Add(new ReportParameter("ReportTitle","My Report");
this.Report1.LocalReport.SetParameters(reportParms1);

rdlc代码:

<ReportItems>
<Textbox name="ReportTitle">
<Value>=Parameters!ReportTitle.Value>
</Textbox>
</ReportItems>

我在出现异常错误 setParameter()Line

异常为“本地报表处理期间发生错误” 内部异常是“报告的定义无效” 内部异常为“文本框的值表达式引用了不存在的报表参数

解决方法

在使用前,您需要在RDLC中定义一个ReportParameter

<ReportParameters>
    <ReportParameter Name="ReportTitle">
        <DataType>String</DataType>
        <Prompt>ReportTitle</Prompt>
    </ReportParameter>
</ReportParameters>

在Visual Studio中,您还可以使用 View> Report Data ,而不是直接修改RDLC。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...