Is there a proper way to reference the fields of a ssrs report from the embedded code of an ssrs report?
When I try to use Fields!Program.Value
I get the following error --
There is an error on line 3 of custom code: [BC30469]
Reference to a non-shared member requires an object reference.
Upon googling I found you could reference the Parameters of a report by prepending Report.
at the beginning. So I tried this Report.Fields.Program.Value
.
That results in the following error...
There is an error on line 3 of custom code: [BC30456] 'Fields' is not a member of 'Microsoft.ReportingServices.ReportProcessing.ExprHostObjectModel.IReportObjectModelProxyForCustomCode'.
So... in summary, is there a way to reference the fields from the embedded code. I figured out I could pass the field vals to the function itself but I would prefer to reference the fields directly.
Seth
You have to pass it in as a parameter.
=Code.ToUSD(Fields!StandardCost.Value)
You do have two other alternatives to passing by parameter, though neither is very pretty.
(Beware! After I wrote the following paragraph I discovered defaults from queries are not supported in local processing mode so this first solution may not be viable for you as it was not for me.)
You can create a hidden report parameter with a default value set from a dataset, then reference this with the
Report.Parameters!MyParam.Value
syntax. You have to be careful when testing this, as (at least in BI studio 2005) the report parameters don't seem to get reliably re-initialised from the DB in the Preview tab.Alternatively you can create a hidden textbox on the report with its text set from a dataset, and then reference the textbox from code. In this case you have to pass the
ReportItems
object as a parameter, but the slight advantage is that it is only ever one extra parameter. Be sure to strongly type the parameter when declaring it:The code will work in BI studio without the type declaration but for me it caused errors with the report viewer control in local processing mode if '
as ReportItems
' was not present.In either case, this is only really useful for page level data, so functions for use in a table should still take parameters.