ASP.Net Report Viewer Using Report Server

brasso_42
brasso_42 used Ask the Experts™
on
Hi

I'm using the report viewer in VS2010 to view a report I’ve created in MSSQL 2008 Reporting Services.  

If I view the report through MSSQL Reporting services it works fine.  It has 2 parameters.  If I delete the parameters it works fine through the report viewer in VS2010.

How to I pass parameters from my ASP page to the report server?

Thanks

Brasso


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I provided a sample below (VB.NET - just use a converter to switch this to C# if you are using C#) in passing two parameters.  I hope this helps.
            Dim Parameters As List(Of ReportParameter) = New List(Of ReportParameter)
            Dim strVal() As String = Nothing
            Dim str As String = String.Empty
            '' First Parameter
            str = "ParameterLabel1 ParameterValue1"
            strVal = str.Split(" "c)
            Parameters.Add(New ReportParameter("ParameterName1", strVal, False))  ''False here means Not Visible.
            '' Second Parameter - only if you need it.
            str = "ParameterLabel2 ParameterValue2"
            strVal = str.Split(" "c)
            Parameters.Add(New ReportParameter("ParameterName2", strVal, False))  ''False here means Not Visible.
            ReportViewer1.ServerReport.ReportPath = "Your Report Path"
            ReportViewer1.ServerReport.SetParameters(Parameters)
            ReportViewer1.ProcessingMode = ProcessingMode.Remote
            ReportViewer1.ServerReport.Refresh()

Open in new window

By the way, the sample in my previous post is based on multi-valued parameters.  If you have only single values, try the following code.  Also, for further information on the ReportParameter, check the link below:

http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.reportparameter.reportparameter.aspx


            Dim Parameters As List(Of ReportParameter) = New List(Of ReportParameter)
            Dim str As String = String.Empty
            '' First Parameter
            str = "ParameterValue1"
            Parameters.Add(New ReportParameter("ParameterName1", str, False))  ''False here means Not Visible.
            '' Second Parameter - only if you need it.
            str = "ParameterValue2"
            Parameters.Add(New ReportParameter("ParameterName2", str, False))  ''False here means Not Visible.
            ReportViewer1.ServerReport.ReportPath = "Your Report Path"
            ReportViewer1.ServerReport.SetParameters(Parameters)
            ReportViewer1.ProcessingMode = ProcessingMode.Remote
            ReportViewer1.ServerReport.Refresh()

Open in new window

Author

Commented:
Hi

This looks like what I want, but how do I apply this to my page/report?  Is it on page load?

Sorry abit new to this.  I understand the code you've given Just not sure how to apply it.

Thanks

Brasso


Yes.  You can start putting it in page load.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
               '' Put it here.
        End If
End Sub

Author

Commented:
Hi

My end solution was to just drop in a blank report view and make visible set to false then put 2 dropdownlists in for my variables and a "run report" button the code be hind which is below.

Many thanks for you help

Brasso
        ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://?.?.?.?/reportserver")
        ReportViewer1.ServerReport.ReportPath = "/preject/reportname"
        Dim Parameters As List(Of ReportParameter) = New List(Of ReportParameter)
        Dim str As String = String.Empty
        Dim str2 As String = String.Empty

        str = DropDownList1.SelectedValue
        str2 = DropDownList2.SelectedValue

        Parameters.Add(New ReportParameter("Pram1", str, False))
        Parameters.Add(New ReportParameter("Pram2", str2, False))

        ReportViewer1.ServerReport.SetParameters(Parameters)




        ReportViewer1.ProcessingMode = ProcessingMode.Remote
        ReportViewer1.Visible = True
        ReportViewer1.ServerReport.Refresh()

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial