How to pass parameters to reports in reportbook

4 posts, 0 answers
  1. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 31 Mar 2010 Link to this post

    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 
                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.
  2. Hrisi
    Hrisi avatar
    221 posts

    Posted 05 Apr 2010 Link to this post

    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,
    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.
  3. DevCraft R3 2016 release webinar banner
  4. Lee
    Lee avatar
    16 posts
    Member since:
    Dec 2010

    Posted 14 Sep 2011 Link to this post

    Was this ever solved, I am trying to do the same thing.
  5. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 14 Sep 2011 Link to this post

    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.ContentType = result.MimeType
            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))
        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()
            Dim cs As New ConnString
            Me.SqlDataSource1.ConnectionString = cs.AAIOMSConnString()
        End Sub
        Public Property setEmployeeNumber() As String
                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.
Back to Top