none
Reportviewer Set/GetParameters() How to? RRS feed

  • Question

  • Hello everyone

    I have a reportviewer on my webform. It currently loads the report just fine.  I pass one known parameter to the report that is required for it to load.  I want to change the other parameters.  When I change one, using the drop down list, the page just refreshes back to default values.  So I added a IsPostBack method.  Now when I do I get a "Specified argument was out of the range of valid values".  I assume this is because I'm not passing back the other three parameters that exist for this report.  How do I get the parameter values when I make a change and then set them?  I have hundreds of reports with all different parameter names.  Many of them are even multi-value.  How do I get/set the parameters even if I don't know their names?  Attached is my current code.

     

    Sub Page_Load(ByVal sender As Object, ByVal ex As System.EventArgs) Handles Me.Load
        cid = Request.Cookies("useraccess").Value
        Dim ReportViewer1 As ReportViewer = New ReportViewer
        ReportViewer1 = Me.ReportViewer1
        form1.Controls.Add(ReportViewer1)
        If Page.IsPostBack Then
          Exit Sub
        ElseIf Not Page.IsPostBack Then
          strclientid = Request.Cookies("clientid").Value
          cid = Request.Cookies("useraccess").Value
          ReportViewer1.ProcessingMode = ProcessingMode.Remote
          ReportViewer1.ServerReport.ReportServerUrl = New System.Uri("http://myweb/RS08")
          ReportViewer1.ServerReport.ReportPath = "/foldername/reportname"
          ReportViewer1.ShowCredentialPrompts = False
          ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials
          'cid is the string value: Demo1,Demo2,Demo3 etc.
          Dim aryCID() As String = cid.Split(",")
          Dim paramList As New List(Of ReportParameter)()
          Dim param As New ReportParameter("CID")
          ' Create the string array of values to pass
          Dim values As String() = New String() {}
          ' Add a range of elements from an array to the end of the StringCollection.
          param.Values.AddRange(aryCID)
          ' Add the parameter to the list of ReportParameters
          paramList.Add(param)
    
          ReportViewer1.ServerReport.SetParameters(paramList)
        End If
      End Sub

     

    Wednesday, June 16, 2010 7:07 PM

Answers

  • Here is the issue:

     

        Dim ReportViewer1 As ReportViewer = New ReportViewer
        ReportViewer1 = Me.ReportViewer1
        form1.Controls.Add(ReportViewer1)

     

    Why am I adding the ReportViewer1 control to the page again everytime it loads?!  WHY!  No wonder I had such horrible param issues. 

    • Marked as answer by jrjohnson3 Friday, June 18, 2010 12:15 AM
    Friday, June 18, 2010 12:15 AM

All replies

  • Dim ParamsInfo As ReportParameterInfoCollection = ReportViewer1.ServerReport.GetParameters()
          For Each p As ReportParameterInfo In ParamsInfo
            Dim ParamName As New ReportParameter(p.Name)
            ParamValues = p.Values
            ParamName.Values.Add(ParamValues.ToString)
            paramList.Add(ParamName)
          Next
          ReportViewer1.ServerReport.SetParameters(paramList)

    I've tried adding this code to my IsPostBack section but it gives me the error:  

    Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Collections.ObjectModel.ReadOnlyCollection`1[System.String]' to type 'System.Object[]'.

    Source Error:

    Line 55:       For Each p As ReportParameterInfo In ParamsInfo
    Line 56:         Dim ParamName As New ReportParameter(p.Name)
    Line 57:         ParamValues = p.Values
    Line 58:         ParamName.Values.Add(ParamValues.ToString)
    Line 59:         paramList.Add(ParamName)

     

     

     

     

    Wednesday, June 16, 2010 8:14 PM
  • No one has any ideas?
    Thursday, June 17, 2010 7:30 PM
  • Here is the issue:

     

        Dim ReportViewer1 As ReportViewer = New ReportViewer
        ReportViewer1 = Me.ReportViewer1
        form1.Controls.Add(ReportViewer1)

     

    Why am I adding the ReportViewer1 control to the page again everytime it loads?!  WHY!  No wonder I had such horrible param issues. 

    • Marked as answer by jrjohnson3 Friday, June 18, 2010 12:15 AM
    Friday, June 18, 2010 12:15 AM