Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide columns dynamically in rdlc report

How we can hide columns dynamically in rdlc reports in MVC 2?

Is it is possible using external parameters? How we can programmatically control the visibility of columns in rdlc reports?

like image 775
Null Pointer Avatar asked Jun 22 '11 10:06

Null Pointer


2 Answers

You don't want to use the Hidden property, you actually want to select the column, Right Click and select Column Visibility. Once in here you can use an expression to set the visibility based on a parameter, something like this:

= iif(Parameters!column_visible.Value = 1, false, true)

Hidden doesn't work in this instance because you're not actually applying it to an object like you are when you select something like a textbox.

like image 178
MrEdmundo Avatar answered Nov 09 '22 22:11

MrEdmundo


Following are the steps to hide the column

1) Add a boolean parameter with name column_visible in your report

2) Right Click on desired column and select Column Visibility.

3) Select the option "show or hide based on an expression"

4) add following formula

= iif(Parameters!column_visible.Value = "True", false,true)

5) Add following code in c# file where you are assigning value to above added parameter

ReportParameter[] parameters = new ReportParameter[1];
if (condition)
{
   parameters[0] = new ReportParameter("column_visible", "True");
}
else
{
 parameters[0] = new ReportParameter("column_visible", "False");
}          
this.reportViewer1.LocalReport.SetParameters(parameters);
like image 28
Asif Avatar answered Nov 09 '22 21:11

Asif