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

How to pass parameters to reports in reportbook

3 Answers 324 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
AkAlan
Top achievements
Rank 2
AkAlan asked on 31 Mar 2010, 05:40 PM
I am looking for a way to create either a report book or a report with several sub reports each of which have their own parameters. All my current reports are standalone and I don't use a report viewer. I am using the new sqlDataSource and setting the parameters in Public Properties like this:
 Public Property setSiteID() As Integer 
        Get 
            Return CInt(Me.SqlDataSource1.Parameters.Item("@SiteID").Value)  
        End Get 
        Set(ByVal siteID As Integer)  
            Me.SqlDataSource1.Parameters.Add("@SiteID", DbType.Int32, siteID)  
        End Set 
    End Property 
I pass the parameter from codebehind of a button like this:
Dim tF As New TelerikFunctions  
Dim strSite As String = ddlSite.SelectedValue.ToString  
Dim rv = New D007RwpSchedule()  
rv.setSiteID = strSite  
tF.ExportToPDF(rv) 'The class tf exports the report to pdf 
So I have several reports that my users have to print every week but they want to be able to just click one button and have all the reports print at once. My problem is that I doon't know how to pass parameters to the individual reports. Does anyone have a solution to this? Thanks for any help.

3 Answers, 1 is accepted

Sort by
0
Hrisi
Telerik team
answered on 05 Apr 2010, 03:42 PM
Hello Alan,

Can you help us by providing your sample project? This will avoid unnecessary general suggestions from us. To do this you will have to open a support ticket. Thank you in advance.

Sincerely yours,
Hrisi
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Lee
Top achievements
Rank 1
answered on 14 Sep 2011, 05:12 PM
Was this ever solved, I am trying to do the same thing.
0
AkAlan
Top achievements
Rank 2
answered on 14 Sep 2011, 05:25 PM
I was able to do what I had asked, that is to pass a parameter to a report that exports directly to PDF and have it open without using the report viewer. I still use this solution although I am going to be exploring other options down the road. Here is what I have done.First create a class in the App_Code folder, I called it TelerikFunctions
Imports Microsoft.VisualBasic
Imports Telerik.Reporting.Processing
Public Class TelerikFunctions
    Inherits System.Web.UI.Page
    Public Function ExportToPDF(ByVal reportToExport As Telerik.Reporting.Report) As Telerik.Reporting.Report
 
        Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor()
        Dim result As RenderingResult = reportProcessor.RenderReport("PDF", reportToExport, Nothing)
        Dim fileName As String = result.DocumentName + ".pdf"
        HttpContext.Current.Response.Clear()
        HttpContext.Current.Response.ContentType = result.MimeType
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Private)
        HttpContext.Current.Response.Expires = -1
        HttpContext.Current.Response.Buffer = True
        'Uncommenting the following line will prompt user to Open Save or Cancel. Otherwise report opens in new window
        HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("{0};FileName=""{1}""", "attachment", fileName))
        HttpContext.Current.Response.BinaryWrite(result.DocumentBytes)
        HttpContext.Current.Response.End()
    End Function
End Class

I use a SqlDataSource for the reports datasource.
Then in the Code Behind of my report I add code to connect to a connection string I created in a class called ConnString (located in the report library) and add properties that I can pass the parameter to like this
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports Telerik.Reporting
Imports Telerik.Reporting.Drawing
 
Partial Public Class HrIndividualTraining
    Inherits Telerik.Reporting.Report
    Public Sub New()
        InitializeComponent()
        Dim cs As New ConnString
        Me.SqlDataSource1.ConnectionString = cs.AAIOMSConnString()
    End Sub
 
    Public Property setEmployeeNumber() As String
        Get
            Return CChar(Me.SqlDataSource1.Parameters.Item("@EmployeeNumber").Value)
        End Get
        Set(ByVal employeeNumber As String)
            Me.SqlDataSource1.Parameters("@EmployeeNumber").Value = employeeNumber
        End Set
    End Property
End Class

Then in the code behind of the aspx page where I what to open the report from I add this code

Imports System.Data.SqlClient
Imports System.Data
Imports FacilitiesReportsLibrary
 
Partial Class HumanResources_Training
    Inherits System.Web.UI.Page
 
    Protected Sub btnPrintTraining_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintTraining.Click
 
 
 
        Dim tF As New TelerikFunctions
        Dim rv = New HrIndividualTraining()  'This is the report itself
        rv.setEmployeeNumber = myParam
        tF.ExportToPDF(rv)     'opens report directly as a pdf window
    End Sub
End Class

My report library is FacilitiesReportsLibrary. Post back if you need more help with this.
Tags
General Discussions
Asked by
AkAlan
Top achievements
Rank 2
Answers by
Hrisi
Telerik team
Lee
Top achievements
Rank 1
AkAlan
Top achievements
Rank 2
Share this question
or