Pro SQL Server 2012 Reporting Services

(sharon) #1
CHAPTER 9  RENDERING REPORTS FROM .NET APPLICATIONS

Upon loading, you’ll see a form like Figure 9-9, which displays a series of combo boxes, each
containing the valid values for the report parameters. You won’t be able to see this in full view until we
add the code to open this parameter form from the main form. We will be performing that step shortly in
the chapter.


Figure 9-9. The Parameters dialog box


Rendering the Final Report


To finish your SSRS 2012 Windows Forms viewer application, you need to set the parameters’ local
variables to the parameter values the user has selected so that you can retrieve them from the
ViewerRVC.cs form, using a property you will create in the GetParameters class called Parameters. You
will populate the parameters variable by creating a method called ViewerParameters.
Make sure the GetParameters form is displayed in design mode, and double-click the OK button.
This will create a new event handler method called buttonOK_Click automatically and set it up to be run
anytime the OK button on our form is pressed. To the buttonOK click event handler, add the code shown
in Listing 9-10.


Listing 9-10. The buttonOK click Event Handler for the OK Button


private void buttonOK_Click(object sender, EventArgs e) {
parameters = ViewerParameters();
this.DialogResult = DialogResult.OK;
Close(); }


The method that it calls, ViewerParameters, simply iterates through the combo boxes and creates an
array of ReportParameters, which are essentially name-value pairs used by the Report Viewer control, as
shown in Listing 9-11. You will need to add this entire method to your GetParameters class manually.
Let’s discuss what this method does before as well.
Our ViewerParemeter method first counts the number of controls that hold values and then
initializes an array of report parameters to be used as the return value. It then looks through each control
inside of the parameter panel we set up and tests if that control is a combo box, which is the type we

Free download pdf