Monday, May 26, 2014

Configuring the SSRS Reports to Asp.Net for Locally

Step 1:- Creating the one sample .rdlc file report from SSRS templete
Step 2:- Add Reference to the project “Microsoft.ReportViewer.WebForms

<%@ Register
Assembly="Microsoft.ReportViewer.WebForms,
Version=10.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
       Namespace="Microsoft.Reporting.WebForms"
TagPrefix="rsweb" %>

Step 3:-Add this report tag

<rsweb:ReportViewer
ID="ReportViewerForCSDRS"
runat="server"
ShowPrintButton="true"
       Font-Names="Verdana"
       Visible="true"
       Font-Size="8pt"
       InteractiveDeviceInfos="(Collection)"
       WaitMessageFont-Names="Verdana"
       WaitMessageFont-Size="14pt"
       Width="100%"
       Height="600px"
       ShowBackButton="False"
       ShowDocumentMapButton="False"
       ShowFindControls="False"
       ShowParameterPrompts="False"
       ShowExportControls="True">
</rsweb:ReportViewer>


Step 4:- Full the dataset from the data base

ClsRptPL objPL = new ClsRptPL();
objPL.FromDate = Convert.ToDateTime(Request.QueryString["FromDate"]);
objPL.ToDate = Convert.ToDateTime(Request.QueryString["ToDate"]);


DataSet ds = new DataSet();

ds=  (fill the data set)

Step 5:- Bind data set to the report datasource

ReportDataSource reportDSHeader = new ReportDataSource("DataSetName", ds.Tables[0]);
ReportViewerForCSDRS.LocalReport.DataSources.Clear();
ReportViewerForCSDRS.LocalReport.EnableExternalImages = true;
ReportViewerForCSDRS.LocalReport.DataSources.Add(reportDSHeader);

Note: “DataSetName” Here displaying the name of the dataset is same as the Report Dataset name while creating the RDLC report

Step 5:- With Parameters report

Here we configure the report parameters

Make Shure that the parameter name is as same as the report parameter name



ReportParameter[] repparams = new ReportParameter[2];

repparams[0] = new ReportParameter();
repparams[0].Name = "FromDate";
repparams[0].Values.Add(objPL.FromDate.ToString());

repparams[1] = new ReportParameter();
repparams[1].Name = "ToDate";
repparams[1].Values.Add(objPL.ToDate.ToString());

ReportViewerForCSDRS.LocalReport.SetParameters(repparams);

ReportViewerForCSDRS.LocalReport.ReportPath = Server.MapPath("ReportRDLC\\PaymentReceipt.rdl"); 

ReportViewerForCSDRS.LocalReport.Refresh();
ReportViewerForCSDRS.ShowExportControls = true;
ReportViewerForCSDRS.ShowReportBody = true;
ReportViewerForCSDRS.ShowToolBar = true;

NOTE: Make sure to add this code in the web config file 

 <system.webServer>
  <handlers>
    <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

</handlers>
</system.webServer>

---------------------

<system.web>
 <compilation debug="true" targetFramework="4.5">

  <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </buildProviders>


  <httpHandlers>
   <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        validate="false" />

   </httpHandlers>

 </compilation> 

</system.web>


Also Export for PDF and Excel

        Warning[] warnings;
        string[] streamids;
        string mimeType, encoding, extension;
        string ReportName = string.Empty;

protected void imgpdf_Click(object sender, ImageClickEventArgs e)
        {
            //extension = ".pdf";
            ReportName = "SampleReceipt";
            byte[] bytes = ReportViewerForCSDRS.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
            Response.ContentType = "application/excel";
            Response.AddHeader("Content-disposition", "filename=" + ReportName + "." + extension);

            Response.OutputStream.Write(bytes, 0, bytes.Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.Flush();
            Response.Close();
        }

protected void imgexcel_Click(object sender, ImageClickEventArgs e)
        {

            byte[] bytes = ReportViewerForCSDRS.LocalReport.Render("EXCEL", null, out mimeType, out encoding, out extension, out streamids, out warnings);
            Response.ContentType = "application/excel";
            Response.AddHeader("Content-disposition", "filename=" + ReportName + "." + extension);

            Response.OutputStream.Write(bytes, 0, bytes.Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.Flush();
            Response.Close();
        }




For Complete Proper look and fee for the SSRS Report design in aspx


<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .overlay
        {
            position: fixed;
            z-index: 98;
            top: 0px;
            left: 0px;
            right: 0px;
            bottom: 0px;
            background-color: #EBEBEB;
            filter: alpha(opacity=80);
            opacity: 0.8;
        }
        #ctl00_ContentPlaceHolder1_rptCommon_ctl05
        {
            background-color: White !important;
            background-image: none !important;
            text-align: left !important;
        }
        #P91bea07e815a4c2187960cfbaecf3a3e_1_oReportCell
        {
            width: 10% !important;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h2 class="module-title" align="center">
        <asp:Label runat="server" ID="lblScreenHeader" Text="" Width="1090px" Font-Size="Medium"
            Style="text-decoration: underline" /></h2>
    <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" EnablePageMethods="true"
        EnablePartialRendering="true" LoadScriptsBeforeUI="true">
    </asp:ScriptManager>
    <table align="right">
        <tr align="right">
            <td>
                <asp:ImageButton ID="imgexcel" runat="server" ImageUrl="~/images/excel.jpg" Width="30px"
                    Height="30px" OnClick="imgexcel_Click" ToolTip="Export to Excel" />
                <asp:ImageButton ID="imgpdf" runat="server" ImageUrl="~/images/pdf.png" Width="30px"
                    Height="30px" OnClick="imgpdf_Click" ToolTip="Export to Pdf" />
            </td>
        </tr>
        <tr align="right">
            <td>
                &nbsp;
            </td>
        </tr>
        <tr align="center">
            <td>
                <div style="width: 1103px; overflow:auto;">
                    <rsweb:ReportViewer ID="rptCommon" runat="server" ShowPrintButton="true" Font-Names="Verdana"
                        Visible="true" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana"
                        WaitMessageFont-Size="14pt" Width="100%" Height="100%" ShowBackButton="False"
                        ShowDocumentMapButton="False" ShowFindControls="False" ShowParameterPrompts="False"
                        ShowExportControls="True" SizeToReportContent="true" ShowPageNavigationControls="True"
                        ShowToolBar="False">
                    </rsweb:ReportViewer>
                </div>
            </td>
        </tr>
    </table>
</asp:Content>


Execute the project and check

For any clarifications or queries please don’t hesitate to call or Email

Phone :- + 91-9492179390


Email :- lannam@technobrainltd.com (or) lokeshtec@gmail.com 
Read More »