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

Setting Report Parameters in ReportViewer

3 Answers 543 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike O'Dell
Top achievements
Rank 1
Mike O'Dell asked on 19 Oct 2009, 01:53 AM

I have a web page (page1) that calls another page including the ReportViewer control.  Page1 includes a button that when clicked redirects to the ReportViewer page.  The call redirection from Page1 to the ReportViewer page includes 2 parameters in the QueryString.  One parameter tells the ReportViewer which report to display from my report lib class.  The other parameter is an ID I want to use in the report codebehind when building the datasource (e.g. Where customerID = paramID).  I don't want to use the ID value as a filter.

The parameter, paramID, is already defined in the report designer with no Value.

In the ReportViewer, how do I set the report parameter, paramID, to the querystring value so that it will be used in the SQL query for the report's datasource?

In the ReportViewer page codebehind I'm trying the following but it doesnt' work:

 

 

Case "rptMyReport"    'this is the report name from the querystring

 

 

 

  Dim appId As String = Request.QueryString("appId")    'this is passed from the first web page (Page1)

 

 

  TryCast

 

(ReportViewer1.Report, wwnReports.rptMyReport).ReportParameters("paramAppId").Value = appId

 

 

  Me.ReportViewer1.Report = New wwnReports.rptMyReport

 

3 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 19 Oct 2009, 12:29 PM
Hello Mike,

The problem is that you set the parameter value to the report instance assigned to the viewer and then on the next line you set a new instance of the report to the ReportViewer.Report property, which would have no clue about the param value you've just set.
The best solution would be to instantiate the report, set its properties and assign it to the viewer:

wwnReports.rptMyReport report = New wwnReports.rptMyReport
report.ReportParameters("paramAppId").Value = appId
Me.ReportViewer1.Report = report

Kind regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mike O'Dell
Top achievements
Rank 1
answered on 19 Oct 2009, 03:37 PM

Thanks.  That makes sense.  I also realize that since I'm using the parameter to build up a DataTable that will be used as the report's DataSource I need to do this in the NeedDataSource event.  However, now when the report details section ItemDataBound runs there is an error saying the DataRowView column name doesn't exist.

Here's the sequence of processing -

The report viewer page creates the report object, sets the parameter, then sets the report property of the viewer control :

 Case "rptLearnerAppScreeningSection"  
                            Dim report As New wwnReports.rptLearnerAppScreeningSection  
                            report.ReportParameters("paramAppId").Value = appId 
                            Me.ReportViewer1.Report = report 

After the ReportViewer1.Report property is set, the NeedDataSource event is fired.  In the NeedDataSource event code I create a DataTable (oReportTable) and fill it with the desired data.  In debug mode, I can look at oReportTable before it is assigned to the DataSource property and see it has the desired values.
 'create a dataTable that will be bound to the report  
        Dim oReportTable As New DataTable  
        oReportTable.Columns.Add("LearnerFirstName", String.Empty.GetType())  
        oReportTable.Columns.Add("LearnerLastName", String.Empty.GetType()) 
.
.
.  
'add the row to the table to be bound to the report  
        oReportTable.Rows.Add(learnerFirstName, learnerLastName, email, credentials, scope, learnerId, semester, dateOfBirth, homePhone, workPhone, mobilePhone, preferredPhone, decision, decisionDate, approverFirstName, approverLastName, homeAddress, homeCity, homeState, homeZip, homeCountry, appFeeMetroState, appFeeWebWoc, lorPeer, lorSupervisor, referencesAreFavorable, professionalGoalStatement, professionalHistory, transcriptsBA_BS, transcriptsBSN_BAN, transcriptsMSN, GPA)  
 
        'set the report data source to the DataTable  
        Me.DataSource = oReportTable 

Next, the detail section ItemDataBound fires.
  Private Sub DetailSection1_ItemDataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailSection1.ItemDataBound  
        'Get the detail section object from sender  
        Dim section As Processing.DetailSection = DirectCast(sender, Processing.DetailSection)  
 
        'From the section object get the DataRowView  
        Dim dataRowView As DataRowView = DirectCast(section.DataItem, DataRowView)  
 
 
        'First Name  
        '**************  
        Dim itemsFirstName As Processing.ReportItemBase() = DirectCast(section.Items.Find("txtFirstName", False), Processing.ReportItemBase())  
        Dim txtFirstName As Processing.TextBox = TryCast(itemsFirstName(0), Processing.TextBox)  
        If (Not IsDBNull(dataRowView("LearnerFirstName"))) Then  
            txtFirstName.Value = dataRowView("LearnerFirstName")  
        Else  
            txtFirstName.Value = "" 
        End If 

The error happens on the line: 
txtFirstName.value = dataRowView("LearnerFirstName")

The error is:
LearnerFirstName is neither a DataColumn nor a DataRelation for table MainTable.

I'm using Reporting 2008 Q2.  Why isn't the DataRowView column name recognized?

Thanks.


0
Steve
Telerik team
answered on 19 Oct 2009, 04:09 PM
Hello Mike O'Dell,

It seems that you are looking at some old documentation prior the Q1 release. Please review the following KB article which explains why DataRowView is not recognized: ReportItemBase.DataItem property (Telerik.Reporting.Processing) has been replaced by property DataObject.
Another incorrect thing I've noticed is that you are setting the DataSource to the definition report object, when you should use the processing report object in the NeedDataSource event i.e.:

Me.DataSource = oReportTable should be

(TryCast(sender, Telerik.Reporting.Processing.Report)).DataSource = oReportTable


Greetings,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Mike O'Dell
Top achievements
Rank 1
Answers by
Steve
Telerik team
Mike O'Dell
Top achievements
Rank 1
Share this question
or