Limit the options for a dropdown list in ReportViewer Control

984 views Asked by At

I have a reportviewer control in remote mode which loads a report that has nine parameters. Under certain conditions, I want to limit the options of one of those parameters (a dropdown list) in the report. If I do this:

protected void Page_Load(object sender, EventArgs e)
{
  var rpt = ReportViewer1.ServerReport;
  var param = rpt.GetParameters()[3];
  var option = param.ValidValues[0];
  param.ValidValues.Clear();
  param.ValidValues.Add(option);
}

then the first time I load the page, only that single option appears. When I click the run report button and the report refreshes, all of the original options are back in the list, and I receive an index out of range error in the report.

Is it possible to do this in the page code?

2

There are 2 answers

1
shane carvalho On

Is it possible to evaluate the filtering conditions from within the report itself? If so, I would alter the report to filter the parameter list dataset using an expression or stored procedure and not depend on modifying report viewer.

0
Alan Cortez On

I would add a new parameter to the report itself called @Top. By default the value is something you know is too high, like 1000.

The dataset for your dropdown would then be modified to

SELECT TOP @Top
(your original query here)

Then in your PageLoad you can pass a value to the ReportViewer setting @Top = 1. This will then limit your dropdown to the first option only.