问题
I want to try and implement a parameter which will allow users to dynamically choose which columns are going to be shown in a report. An idea is to create a multiple value parameter which has column names. After user hit View Report I want to try iterate over columns and selected values to join visibility.
How I can iterate over columns inside a tablix?
How I can iterate over multiple values of a parameter, so I can find if some value is selected or not?
I am using MS SQL Reporting Services 2012.
回答1:
For a table, i.e. fixed columns, you can use the following approach. It's not really loop based so much as an individual distinct visibility check for each column based on a parameter selection.
Set up a multi-valued parameter that lists the columns that can be displayed/hidden.
Then, for each of these columns in the actual table, set the Column Visibility to use an expression based on the parameter:
The expression would something like:
=IIf(InStr(Join(Parameters!IncludedColumn.Value, ","), "Col1") > 0, false, true)
What this is doing is constructing a string of all selected values for the IncludedColumn parameter, then checking if a certain column identifier is included; Col1 for this particular column. You'd use different constants for each column.
So when running the report this approach can hide/display columns based on a parameter selection.
All columns selected:
Some columns selected:
来源:https://stackoverflow.com/questions/16372103/iterate-over-columns-of-a-report-to-dynamically-show-hide-them