Reporting Services


This code helps in connecting with the reports hosted in the MS-SSRS through .NET code. (Example is with C# 4.0 Framework)
----------------------------------------------------------------------------------------------------------------
Microsoft.Reporting.WebForms.ReportParameter[] RptParameters;


            reportViewer.ServerReport.ReportServerUrl = new System.Uri(ConfigurationManager.AppSettings["ReportServerURL"]);
            reportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
            reportViewer.ToolBarItemBorderColor = System.Drawing.Color.PowderBlue;
            reportViewer.ToolBarItemBorderStyle = BorderStyle.Double;


            string strUserName = ConfigurationManager.AppSettings["UserName"].ToString();
            string strPassword = ConfigurationManager.AppSettings["Password"].ToString();
            string strDomain = ConfigurationManager.AppSettings["Domain"].ToString();
            reportViewer.ServerReport.ReportServerCredentials = new ReportCredentials(strUserName, strPassword, strDomain);
            string strReport = string.Empty;
            strReport = ConfigurationManager.AppSettings["ReportsFolder"] + Request.QueryString["ReportName"].ToString();


Below snippet shows on how to pass parameters to the report  :


                this.reportViewer.ServerReport.ReportPath = strReport;
                RptParameters = new Microsoft.Reporting.WebForms.ReportParameter[1];
                RptParameters[0] = new Microsoft.Reporting.WebForms.ReportParameter("                                                      <ParameterName>", "<ParameterValue>");               
                this.reportViewer.ServerReport.SetParameters(RptParameters);     
                reportViewer.ServerReport.Refresh();


You can pass any number of parameters to the report. Just make sure that the <ParameterName> matches with the parameter name in the report. 


Report Viewer Design Trouble shoot:

To set the default blue color to the hyperlinks in the subreports/Drill down reports, please use this jQuery Function. 

 function ChangeLinkColorInReport() {

            var reportDocument = eval("ReportFrame<%=reportViewer.ClientID %>").document.getElementById("report").contentWindow.document;
            var reportDiv = reportDocument.getElementById("oReportDiv");
            //Show DrillDown Report HyperLinks
            jQuery(reportDiv).find('a').each(function (i, item) {
                jQuery(item).css('color', 'blue');
                jQuery(item).css('text-decoration', 'underline');
            });
        }

Use that function inside this event of the Report Viewer:


 protected void reportViewer_PageNavigation(object sender, PageNavigationEventArgs e)
        {
            Page.ClientScript.RegisterStartupScript("".GetType(), "ChangeColorBlock", "ChangeLinkColorInReport();", true);      
        }