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

Passing Parameter via Mark-Up or Code Behind Ignored

2 Answers 322 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 2
Iron
Iron
Iron
Mark asked on 20 Oct 2020, 05:19 PM
<telerik:ReportViewer
          ID="reportViewer1"
          Width="90%"
          EnableAccessibility="true"
          PageMode="SinglePage"
          ScaleMode="FitPageWidth"       
          runat="server">
          <ReportSource Identifier="Report1.trdp" IdentifierType="UriReportSource">
              <Parameters>
                  <telerik:Parameter Name="AccountId" Value="25585" />
              </Parameters>
          </ReportSource>
      </telerik:ReportViewer>

 

I tried pass the Parameter via the html and code behind and it seems to be ignored. My Report1.trdp file reads a Stored Procedure passing in the AccountId. I am using a SQL Data source as part of the Report1.trdp file.

protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              this.reportViewer1.ReportSource.Parameters.Add("AccountId", 25585);
          }
      }

2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 23 Oct 2020, 09:55 AM

Hello Mark,

Both of the provided code snippets for setting the parameter value are correct. The process of passing a parameter value from the HTML/code behind to the SQL stored procedure has multiple steps. Please make sure that all of the steps are completed and test again:

  1. Pass the parameter values from the viewer to the report via HTML or code behind (this is correctly implemented).
  2. Make sure that a report parameter exists in the report with the same name (AccountId) and correct type (String or Integer might be suitable for "25585"). The report parameters are present in the Report.ReportParameters property.
    You can test if the value is passed correctly to the report parameter by adding a TextBox somewhere in the report and setting the TextBox.Value to the report parameter's value.
  3. Make sure that a data source parameter exists that is the link between the report parameter and the stored procedure. The data source parameter value should be set to an expression like the following:

    = ReportParameters.AccountId.Value

    You can test that the value is passed correctly to the stored procedure by starting the SQL Server Profiler and examining the sp call.

Regards,
Nasko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Mark
Top achievements
Rank 2
Iron
Iron
Iron
answered on 26 Oct 2020, 02:33 PM

Thanks so much. This was the piece I was missing 

 

Make sure that a data source parameter exists that is the link between the report parameter and the stored procedure. The data source parameter value should be set to an expression like the following:

= ReportParameters.AccountId.Value

Tags
General Discussions
Asked by
Mark
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Nasko
Telerik team
Mark
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or