问题描述
我想在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。