Monday, October 4, 2010

Hide/UnHide Columns In SSRS Report while rendering

We know how to add filters in a report which filter the result set according to the filter expression.

Now, we will see how to Hide and UnHide the columns in a report by using a filter (Parameter).

For this, we need some Custom coding.

Let us see the report..


Now, I want to see only the columns "Sales OrderID", "OrderDate" and "CustomerID"

For this, we need to create a parameter in the report.
The name of the parameter can be anything, and I am naming it "Column"

we will have to First give all the column names as available values.
Then default the parameter to show all these columns.






Now, in the Code section in report properties, add the following custom Code.



Public Shared Function IsColumnSelected(ByRef objMultiValueParam() As Object, ByVal strColumnName As String) As Boolean
Return 0 <>
End Function

Now, in the column group section in the report, when you click on the small arrow, shown in figure, you will see advanced Mode. Click on that, and you will see all the hidden Column Groups. One Group for every column in the report.



Click on each group and in the "Hidden" property of the group, add this code..





For 1st Column Group,
=Not Code.IsColumnSelected(Parameters!Column.Value, "SalesOrderID")

For 2nd Column Group,
=Not Code.IsColumnSelected(Parameters!Column.Value, "OrderDate")

And so on....


Now the report will look like this..


When you select the values in the parameter, the report will only show those columns which you selected in the parameter.

Example,