3

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?

drowned
  • 530
  • 1
  • 12
  • 31
  • The button click event should be running after page_load. Can you verify this is the case? Is the out of range exception occurring on the GetParameters() call because the parameters collection is empty? – moarboilerplate Feb 26 '15 at 19:22
  • The button is actually part of the report, and I haven't been able to find an event handler that works with it directly (I am not the person who developed the report, I'm just supposed to make it work from the site with this special dropdown condition. I know very little about SSRS reports or why there is a button built into it.) I don't know when the exception is happening because it's also sort of "part" of the report. The page doesn't crash out, I literally just get some text "index out of range" in place of where the report would otherwise be. – drowned Feb 26 '15 at 19:31
  • HI, Can you please tell what version of C# and report control you using? – Gaurav Sharma Mar 03 '15 at 13:49

2 Answers2

1

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.

0

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.

shane carvalho
  • 130
  • 1
  • 10
  • I don't know, I have no experience with such things. I think investigating that is my next move, I've spent too much time trying to make the viewer work the way I want. – drowned Feb 27 '15 at 18:07