11

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?

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
Null Pointer
  • 9,089
  • 26
  • 73
  • 118

3 Answers3

32

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.

MrEdmundo
  • 5,105
  • 13
  • 46
  • 58
  • If you use Hidden's property expression and you have more columns at the right, the empty space will remain in between. Thanks @MrEdmundo! – Ramon Araujo Jul 28 '16 at 03:43
  • 1
    @RamonAraujo, Hey did you find a way to overcome the empty space issue when you hide the columns? – Bassel Shmali Oct 30 '18 at 09:26
18

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);
Asif
  • 2,657
  • 19
  • 25
0

Select a column. In properties you have Hidden. property. Then you can set a condition, for example =Parameters!IsColumnHidden.Value.

If you want to do this from C# code I would send a parameter (like above) to the report saying if column should be hidden.

Episodex
  • 4,479
  • 3
  • 41
  • 58