none
dynamically passing params to a report. RRS feed

  • Question

  • I have a report based on a stored proc.

     

    The stored proc has 4 params.

     

    Is there a way to dynamically feed a report the params based on information from a previous webpage?

     

     

     

    Monday, January 21, 2008 10:29 PM

Answers

  • .setting the parameters of a localreport is only one part to loading a viewer via code

     

    You also have to supply any required datasources

     

    and the .RDLC file these parameters are bound to

    DataSet ReportDataSet = new DataSet();

    //load your dataset here

     

     

    string reportTemplate = "myReport.rdlc";

    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RDLCTemplates/" + reportTemplate)

     

     

    ReportDataSource customReportData = new ReportDataSource();

     

     

     

    customReportData.Name = "ReportDataset_ReportData1";

    customReportData.Value = ReportDataSet.Tables[0];

    ReportViewer1.LocalReport.DisplayName = "ReportDescription";

    //pass the reportviewer our datasource

    ReportViewer1.LocalReport.DataSources.Add(customReportData);

    ReportViewer1.LocalReport.Refresh();

    Tuesday, January 22, 2008 5:15 PM

All replies

  • yes you could,  first you need to pass those params to the webpage via whatever method you deem fit.  Then grab those params, and pass them in as ReportParameters.   

     

     

     

    string someInfo = "";

    string moreInfo = "";

    string someStrFromSomewhere = "";

    string someStrVar = "";

     

    ReportParameter group1 = new ReportParameter("Group1Param", someInfo);

    ReportParameter group2 = new ReportParameter("Group2Param", moreInfo);

    ReportParameter reportDesc = new ReportParameter("ReportDescription", someStrFromSomewhere);

    ReportParameter reportInfo = new ReportParameter("ReportStuff", someStrVar);

    ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { group1, group2, reportDesc, reportInfo });

     

     

     

    these parameters would need to be setup in your report beforehand.  To do that, just go to the report designer, and when your viewing your report, in the blank area under the body and footer, right click..and choose parameters.  Add what you need and set the correct data type.

     

    To use the parameters in the report  The expression's based on the above examples would be...

     

    =Parameters!Group1Param.Value

    =Parameters!Group2Param.Value

    =Parameters!ReportDescription.Value

    =Parameters!ReportStuff.Value

    Tuesday, January 22, 2008 2:32 PM
  • This is a good start. I am green on reports.

     

    I used this in my pageload. where I created a webform and dragged the report with the parms on it to the form.

     

    In the page I get this:

    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="765px">

    </rsweb:ReportViewer>

     

    when I put the following in pageload however, I get the error message:

    The source of the report definition has not been specified.

     

     

    ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { YearID, ModelID, MakeID, EngineID });

     

    Tuesday, January 22, 2008 5:09 PM
  • .setting the parameters of a localreport is only one part to loading a viewer via code

     

    You also have to supply any required datasources

     

    and the .RDLC file these parameters are bound to

    DataSet ReportDataSet = new DataSet();

    //load your dataset here

     

     

    string reportTemplate = "myReport.rdlc";

    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RDLCTemplates/" + reportTemplate)

     

     

    ReportDataSource customReportData = new ReportDataSource();

     

     

     

    customReportData.Name = "ReportDataset_ReportData1";

    customReportData.Value = ReportDataSet.Tables[0];

    ReportViewer1.LocalReport.DisplayName = "ReportDescription";

    //pass the reportviewer our datasource

    ReportViewer1.LocalReport.DataSources.Add(customReportData);

    ReportViewer1.LocalReport.Refresh();

    Tuesday, January 22, 2008 5:15 PM