问题
I have an RDLC with multiple tables and for each table, I have a toggle TextBox Item that hides the corresponding table from the report. It works perfectly, however, I don't want these text boxes to be visible in the printed/exported reports. They are really meant for disabling content in the report and not as content themselves. Is there a way to hide those toggle boxes from only Print Layout and exported versions of the report?
I looked at all of the properties of the report textbox and at the available expressions that I can use to toggle visibility, but I didn't find anything that I can use to hide the item. There is a DataElementOutput property that seems to be what I want, but I believe that it is only useful for XML.
回答1:
Late, but there are one solution. You can add a parameter to the report for handle control visibility and in the Print event, change the parameter value and then refresh the report (ReportViewer1.RefreshReport())
回答2:
This can be achieved using a simple visibility toggle. You can use the RenderFormat.IsInteractive variable to determine whether a report is shown in report viewer or is being exported. An MSDN article explains this about this global variable,
Furthermore, a Boolean flag (=Globals!RenderFormat.IsInteractive) determines whether a rendering extension is an interactive renderer, i.e. not an export format. Preview (GDI/Winforms) and HTML viewing are considered interactive renderers.
Set the visibility of the text box you want to hide in the export to the following expression
=NOT(Globals!RenderFormat.IsInteractive)
Refer to the following image (courtesy of blog.hoegaerden.be) to know the values assigned to RenderFormat.IsInteractive
回答3:
You can do some hacks to try to accomplish that like: - setting the text and border on your TextBox to be white so they are not vislble but still clickable - make report bigger than print size (paper size) and move your textboxes out of the print area (they will be printed/exported but not on the same page like your tables) - put your textboxes on top and design them to look like tabs which enable different views (I know, I know, this is not what you asked for :-) )
But the best way to solve this is to split your report in to several reports - for each table one report.
hope this helps!
cheers,
Pero
来源:https://stackoverflow.com/questions/1069500/hide-a-report-item-from-print-export-of-an-rdlc-report