Sunday, February 19, 2012

How to filter a report using an asp.net page

Hi,
I need to filter a single .rdl page in accordance with an option chosen from an asp.net page.
I know how to filter a report within the reporting page. But how can I do the filtering from an asp.net page? For example I have a Report1.rdl that prints out all the locations. I need the same report1.rdl page to print out only for a certain location based on the option I chose from the asp.net page. My asp.net page has 3 buttons. One to for all locations, another for location1, and the other one for location2. Please help. Thanks

1. Add a parameter to the report for location.

2. Modify your SQL code to account for that parameter, ie. WHERE Location = @.Location.

3. In Visual Studio, pass the location parameter value based upon the option chosen.

|||

GregSQL wrote:

1. Add a parameter to the report for location.

2. Modify your SQL code to account for that parameter, ie. WHERE Location = @.Location.

3. In Visual Studio, pass the location parameter value based upon the option chosen.

Thanks Greg. I got 1 and 2 working. Now how do I make the 3rd part? How do I call the parameters from an asp.net page to show the report in a browser? Thanks again for your help.
|||

Code Snippet

Dim param AsNew Microsoft.Reporting.WebForms.ReportParameter

Dim paramarr(0) As Microsoft.Reporting.WebForms.ReportParameter

param = New Microsoft.Reporting.WebForms.ReportParameter("myParameter", DropDownList1.SelectedValue.ToString())

paramarr(0) = param

ReportViewer1.ServerReport.SetParameters(paramarr)

This would set the report parameter myParameter to the selected value of DropDownList1. Remember that the parameterarray's starting index is zero...that typically leads me to off by one errors.

Oh and I was somewhat assuming that you already knew how to use a report viewer component in .NET to display a report in an internet browser. If not, let me know.

No comments:

Post a Comment