locked
How to pass parameters to embedded ReportViewer rdlc report? RRS feed

  • Question

  • User-651208615 posted

    Hi Community    

         In Windows applications for embedded reports all you have to do is create a form, drag a
    TableAdapter onto the form add something like this in the code behind:

    this.Rpt1TableAdapter.Fill(Rpt1DataSet2.RptTable, fromDate, toDate);
    reportViewer1.ProcessingMode = ProcessingMode.Local;
    LocalReport localReport = reportViewer1.LocalReport;
    DataSet dataset = new DataSet("RptDataSet3");
    ReportDataSource dsRpt = new ReportDataSource();
    dsRpt.Name = "TblReport";
    dsRpt.Value = dataset.Tables["ReportTbl"];
    localReport.DataSources.Add(dsRpt);
    ReportParameter[] tblParam = new ReportParameter[2];
    tblParam [0] = new ReportParameter("parfDate", fDate.ToString());
    tblParam [1] = new ReportParameter("partDate", tDate.ToString());
    reportViewer1.LocalReport.SetParameters(tblParam);
    this.reportViewer1.RefreshReport();
     
    But not in ASP.NET.

    I am trying to create an embedded rdlc report in my Web Application.

    So far I have successfully created an embedded report following the steps below:

    Created a dataset in the App_Code folder.

    Created an rdlc file with a table region on it to place the fields in .

    Created a form with a ReportViewer Control on it and chose the rdlc file as the report and for

         the datasource chose the dataset that was created in the App_Code folder.

    this works.

        However, now I want to pass parameters to the report and it is not like doing it in Windows Application
    because the ReportViewer and LocalReport are in the html not the code behind. 

    The first thing I do is try to pass parameters  “From date” and “To Date”  to the report and create those parameters in the rdlc
    but since the ReportViewer and LocalReport keywords are in the html I don’t know how to pass the parameters to the report. 
    Below is how the ReportViewer and LocalReport keywords  looks in the html (along with the datasource):

    <body>
        <form id="form1" runat="server">
        <div>
       
        </div>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" Height="775px" Width="856px">
            <LocalReport ReportPath="CrtReport\AllRpts\MainReport.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="SqlDataSource1"
                        Name="DataSet1_ReportTable" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:DataSetRpt %>"
            SelectCommand="SELECT [LastName], [FirstName], [Address], [From Date], [To Date] FROM [ReportTable]  "></asp:SqlDataSource>
     

        </form>
    </body>

       
    So basically my question is how do I pass parameters to my embedded report?

        Thank you
        Shabeaut

     

    Wednesday, January 19, 2011 5:20 PM

Answers

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 23, 2011 12:04 AM
  • User1471008070 posted

    Hi,

    You have already define the parameters (parfDate/partDate) in the code-behind, then you should utilize these Parameters in your report to filter the report’s data. Firstly, you should create two parameters on the report with the same name(parfDate/partDate), then utilize it in the T-SQL, you could also make use of it in DataSet’s filter or data region’s filter.

    If you have any question, please feel free to ask.

    Thanks,
    Challen Fu <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 24, 2011 5:32 AM

All replies

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 23, 2011 12:04 AM
  • User1471008070 posted

    Hi,

    You have already define the parameters (parfDate/partDate) in the code-behind, then you should utilize these Parameters in your report to filter the report’s data. Firstly, you should create two parameters on the report with the same name(parfDate/partDate), then utilize it in the T-SQL, you could also make use of it in DataSet’s filter or data region’s filter.

    If you have any question, please feel free to ask.

    Thanks,
    Challen Fu <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 24, 2011 5:32 AM