Iterate over columns of a report to dynamically show/hide them?

混江龙づ霸主 提交于 2019-12-11 08:34:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!