This is a migrated thread and some comments may be shown as answers.

Pass parameters from custom UI to reports

5 Answers 264 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
jay
Top achievements
Rank 1
jay asked on 31 Dec 2010, 04:51 AM

Hello,
I started off with the ReportCatalog used in the CSharp.ReportExamples.VS2010 solution from which reports hosted in an asp.net class library are loaded. I went ahead and created a custom parameter UI above my Silverlight reportviewer, but i cannot seem to get the target report (using the Navigate to Report action) to receive the passed parameters from the custom ui. I can navigate to the reports but only the default parameter values set for the reports are used. I have tried using the RenderBegin method but it seems the passed parameters are being ignored. I have read a number of blogs on this, but somehow, things are not working.

How can I wire up the parameters from my Silverlight application to the reports?

Below are snippets of my code:

<my1:ReportViewer Name="rptViewer"
                          …..
                          Report="XXX.ReportsLibrary.ReportCatalog, XXX.ReportsLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                          ReportServiceUri="../Services/ReportService.svc"                                      RenderBegin="rptViewer_RenderBegin"
                          Loaded="rptViewer_Loaded" />

In the code behind of the page hosting the reportviewer, I have:

void rptViewer_RenderBegin(object sender, RenderBeginEventArgs args)
 { 
args.ParameterValues.Clear(); 
args.ParameterValues["dateStart"] = rdpStart.SelectedDate; 
args.ParameterValues["dateEnd"] = rdpEnd.SelectedDate; 
((ReportViewerModel)(rptViewer.DataContext)).ApplyReportParametersCommand.Execute(null);
 
}

One thing I noticed is that the sender is ALWAYS the ReportCatalog. I was expecting that after navigating to ReportX the Sender would be ReportX. So is it that I am trying to apply parameters to the wrong report?

Please help!!!

My last option would be to abandon the idea of custom parameters UI.

Thanks

5 Answers, 1 is accepted

Sort by
0
John S.
Top achievements
Rank 1
answered on 31 Dec 2010, 07:47 AM
Hello Jay,

The following is in VB but hopefully it will be of help.

Below are two blocks of code. The first is a class CReporting in which the parameters are updated and the second code block is a sub routine that uses the class to update the viewer and refresh it.

The sub can just be called from a button click.

John

Imports System.IO
Imports System.Web.UI
Imports Telerik.Reporting.Processing
Imports Telerik.Reporting
Public Class CReporting
  
    Private m_ReportParameters As New ReportParameterCollection
    Private m_ParameterName As String
    Private m_ParameterValue As String
    Private m_ParameterType As ReportParameterType
    Private m_ReportExportFormat As ReportExportType
    Private m_ReportToExport As Telerik.Reporting.Report
  
    Public WriteOnly Property ReportToExport() As Telerik.Reporting.Report
        Set(ByVal value As Telerik.Reporting.Report)
            m_ReportToExport = value
        End Set
    End Property
  
    Public WriteOnly Property ParameterName() As String
        Set(ByVal value As String)
            m_ParameterName = value
        End Set
    End Property
  
    Public WriteOnly Property ParameterValue() As String
        Set(ByVal value As String)
            m_ParameterValue = value
        End Set
    End Property
  
    Public WriteOnly Property ParameterType() As ReportParameterType
        Set(ByVal value As ReportParameterType)
            m_ParameterType = value
        End Set
    End Property
  
  
    Public Sub AddReportParameter()
        m_ReportParameters.Add(m_ParameterName, m_ParameterType, m_ParameterValue)
    End Sub
  
  
    Public Sub LoadParameters()
  
        For Each oParameter As ReportParameter In m_ReportParameters
            m_ReportToExport.ReportParameters(oParameter.Name).Value = oParameter.Value
        Next
  
          
    End Sub
  
  
End Class

Private Sub RefreshViewer()
    Dim oReportOp As New CReporting
    Dim oReport As Telerik.Reporting.Report
    oReport = rvReportViewer.Report
    With oReportOp
            .ReportToExport = oReport
              
            .ParameterName = "EmployeeId"
            .ParameterValue = cmbEmployees.SelectedValue
            .ParameterType = Telerik.Reporting.ReportParameterType.Integer
            .AddReportParameter()
              
            .ParameterName = "CountryName"
            .ParameterValue = cmbCountries.Text
            .ParameterType = Telerik.Reporting.ReportParameterType.String
            .AddReportParameter()
  
          
            .LoadParameters()
              
            rvReportViewer.RefreshReport()
      
    End With
End Sub
0
jay
Top achievements
Rank 1
answered on 31 Dec 2010, 05:15 PM
Thanks, John !
I will convert to C# and check it out.  Can I assume that these code blocks should be added to the ASP.Net Report Library?  I cannot add project reference to this library on the SL4 project, so i am wondering how i can reference the SL4 based reportviewer from the .Net Library.

0
John S.
Top achievements
Rank 1
answered on 31 Dec 2010, 07:39 PM
Jay,

I didn't notice this was for a Silverlight reportviewer so I don't know what differences there are (I haven't used it), but hopefully they use the same type of interface and this helps.

In regards to the last message.....

The code is created within my ASP.NET project (ASP.NET project references the report library). I define the code using a class (CReporting) within my ASP.NET; however, the code could easily be created in the code-behind page instead.

I hope that helps.

John

0
Divya
Top achievements
Rank 1
answered on 15 Apr 2014, 09:52 AM
 ClassLibrary1.StudentAttendanceMonthandSubjectwise myReport = new StudentAttendanceMonthandSubjectwise();
            myReport.DataSource = dsp; 
Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
            
            reportSource.Parameters.Add(new Telerik.Reporting.Parameter("BranchSectionID", int.Parse(ddlsection.SelectedValue)));
            reportSource.Parameters.Add(new Telerik.Reporting.Parameter("AcademicYearID", CoursesSession.Courses.AcademicYearID));
            reportSource.Parameters.Add(new Telerik.Reporting.Parameter("ClassID", int.Parse(ddlcls.SelectedValue)));
            reportSource.Parameters.Add(new Telerik.Reporting.Parameter("SubjectID", int.Parse(ddlsubject1.SelectedValue)));
            reportSource.ReportDocument = myReport;
            reportviewer1.ReportSource = reportSource;  


how to get report through these parameters in telerik reporting
0
Stef
Telerik team
answered on 16 Apr 2014, 05:40 PM
Hi Divya,

This is  a quote from my post in your support ticket #806737  on the same question:

"This can be achieved through the Report Source object that wraps the report. The ReportSource.Parameters collection (key-value pairs) is mapped to the underlying Report.ReportParameters collection by key. Using this approach you can pass also Session variable, as long as they are from the supported by the report parameters types: String, Integer, Float, Datetime, Boolean. You can also reassign the ReportViewer.ReportSource to other Report Source object."


In the ticket you can find more links to our documentation and a demo project. If you need any further help, please use our support ticketing system and address your issue in a single thread to avoid splitting information. The thread can be found after logging into your account and checking Your Support tickets.

Thank you for your understanding.

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
jay
Top achievements
Rank 1
Answers by
John S.
Top achievements
Rank 1
jay
Top achievements
Rank 1
Divya
Top achievements
Rank 1
Stef
Telerik team
Share this question
or