Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing parameter to report viewer

I want to pass a parameter to my report view. I have a drop down list with values from database and a button for displaying the report after selecting an item from the drop down list.

here is the code I wrote for adding the parameter

protected void Button1_Click(object sender, EventArgs e)
{
    RenderReport();
}

protected void RenderReport()
{
    try
    {
        ServerReport serverReport = ReportViewer1.ServerReport;
        ReportViewer1.ProcessingMode = ProcessingMode.Remote;
        try
        {
            serverReport.ReportServerUrl = new Uri("http://hedinaily-pc/Reports_HEDI");
        }
        catch (Exception ex)
        {
            Logger.Error(ex.Message, "");
        }
        serverReport.ReportPath = "~/Diagrammes/PresenceTotale.rdlc";
        ReportParameter employe = new ReportParameter();
        employe.Name = "Employe";
        employe.Values.Add(DropDownList1.SelectedValue);
        ReportViewer1.ServerReport.SetParameters( new ReportParameter[] { employe });
        ReportViewer1.Visible = true;               
    }

    catch (Exception ex)
    {
        Logger.Error(ex.Message, "");

    }

}

Here is the data set of my report

enter image description here

When I check my log file I find this error :

The attempt to connect to the report server failed.  Check your connection information and that the report server is a compatible version.

Can anyone tell me where doe's this error come from. I spent hours searching on google I found this LINK but I couldn't resolve it.


1 Answers

Try it like this...

ReportViewer1.ServerReport.ReportPath = "FooReport.rdlc";
ReportParameter[] reportParameter = new ReportParameter[2];
reportParameter[0] = new ReportParameter("fooFromDate", dateFrom.ToShortDateString());
reportParameter[1] = new ReportParameter("fooDateTo", dateTo.ToShortDateString());
ReportViewer1.ServerReport.SetParameters(reportParameter);
ReportViewer1.ServerReport.Refresh();

Also .Refresh() method must be called so that...report is displayed..

like image 126
Mayank Pathak Avatar answered Sep 13 '25 13:09

Mayank Pathak