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

Passing parameters from Grid to Report

1 Answer 192 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 24 Jun 2009, 04:16 PM
I need the ability to pass a RecordID to a report from a grid.  The report is defined in a separate class (with a reference in the project containing the web forms) with the following code behind:

Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports Telerik.Reporting
Imports Telerik.Reporting.Drawing
Partial Public Class GoalsCalculatorReport
    Inherits Telerik.Reporting.Report
    Public Sub New()
        InitializeComponent()
        Me.DataSource = Nothing
    End Sub

    Private Sub GoalsCalculatorReport_NeedDataSource(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.NeedDataSource
        'Transfer the ReportParameter value to the parameter of the select command    
        Me.SqlDataAdapter1.SelectCommand.Parameters("@PandLID").Value = Me.ReportParameters("PandLID").Value
        Me.SqlDataAdapter1.SelectCommand.Parameters("@NetProfitGoal").Value = Me.ReportParameters("NetProfitGoal").Value
        Me.SqlDataAdapter1.SelectCommand.Parameters("@RaiseFeesByPct").Value = Me.ReportParameters("RaiseFeesByPct").Value
        Me.SqlDataAdapter1.SelectCommand.Parameters("@IncreaseCrownsPerWeek").Value = Me.ReportParameters("IncreaseCrownsPerWeek").Value
        Me.SqlDataAdapter1.SelectCommand.Parameters("@ImproveAcceptanceRatePct").Value = Me.ReportParameters("ImproveAcceptanceRatePct").Value
        Me.SqlDataAdapter1.SelectCommand.Parameters("@ReduceOverheadExpensePct").Value = Me.ReportParameters("ReduceOverheadExpensePct").Value
        Me.SqlDataAdapter1.SelectCommand.Parameters("@IncreaseNewPatientsFromMarketing").Value = Me.ReportParameters("IncreaseNewPatientsFromMarketing").Value
        Me.SqlDataAdapter1.SelectCommand.Parameters("@IncreaseNewPatientsFromReferrals").Value = Me.ReportParameters("IncreaseNewPatientsFromReferrals").Value
        'Take the Telerik.Reporting.Processing.Report instance and set the adapter as   
        'it's DataSource    
        Dim report As Telerik.Reporting.Processing.Report = CType(sender, Telerik.Reporting.Processing.Report)
        report.DataSource = Me.SqlDataAdapter1
    End Sub
End Class



And I've been using the following code to send grid data to another web form.  I just don't know how to use a value from the grid in a report such that when I click on (a button on) a separate record of a grid, the report will show me the data for that particular record.



    Protected Sub RadGridPLPS_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGridPLPS.ItemCommand
        Dim itmITEM As Telerik.Web.UI.GridDataItem = CType(e.Item, Telerik.Web.UI.GridDataItem)
        Dim cell As TableCell = itmITEM("PandLID")
        '        Response.Write(cell.Text)
        Select Case e.CommandName
            Case "Edit"
                Context.Items("PandLID") = cell.Text
                Server.Transfer("PLPStatEntry.aspx")
            Case "Summary"
                Context.Items("PandLID") = cell.Text
                Server.Transfer("Summary.aspx")
            Case "Analysis"
                Context.Items("PandLID") = cell.Text
                Server.Transfer("PracticeAnalysis.aspx")
        End Select
    End Sub



I would also like to use a similar process to be able to send data from the same web form (that contains the report viewer control) to the report.  For example to create my own selection criteria fields and pass them to the report.

Thank you

1 Answer, 1 is accepted

Sort by
0
Tom
Top achievements
Rank 1
answered on 24 Jun 2009, 11:34 PM
I figured out that I can use the following code on the web form to update the value of a parameter on a report:

        Dim Report As Telerik.Reporting.Report
        Report = New PracticeDiagnostxReportsLibrary.GoalsCalculatorReport
        Report.ReportParameters(0).Value = PandLID

And I can simply use context in the page_load event to retrieve the value (previously set in RadGridx_ItemCommand):

        PandLID = CType(Context.Items("PandLID"), String)

... in case anyone else is looking for this.
Tags
General Discussions
Asked by
Tom
Top achievements
Rank 1
Answers by
Tom
Top achievements
Rank 1
Share this question
or