SSRS Report with Asp.net Page



Here I am going to discuss with you, how you can implement your SSRS(SQL Server Reporting Services) with your Asp.net page.
See the below code and check it how it works. I hope you will enjoy.


.aspx page

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Report.aspx.cs" Inherits="_Report" %>

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

   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>SSRS Report</title>
</head>
<body>
    <form id="form1" runat="server">
      
Param 1   <asp:DropDownList ID="ddlPara1" runat="server">
    <asp:ListItem Value="Profit">Profit</asp:ListItem>
    <asp:ListItem Value="Loss">Loss</asp:ListItem>
    </asp:DropDownList>
Param2   txtPara2" runat="server" ></asp:TextBox>

<asp:Button ID="btnReport" runat="server" Text="Show Report"
                        onclick="btnShowReport_Click" />




    <asp:ScriptManager ID="scManager" runat="server"></asp:ScriptManager>

<div style="display:block;">
    <rsweb:ReportViewer ID="rvReport" runat="server" Width="100%">
    </rsweb:ReportViewer>
    </div>
   </form>
</body>
</html>

.aspx.cs page
  protected void Report()
    {
        try
        {
           
            rvReport.Visible = true;
            rvReport.ServerReport.DisplayName = "My Report";

            rvReport.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
            rvReport.ServerReport.ReportServerUrl = new Uri(@"http://localhost/ReportServer");                //your Report Server
            rvReport.ServerReport.ReportPath = "/DTest/RepTest"//Report Path  
            rvReport.ShowParameterPrompts = false;
            rvReport.ShowPrintButton = true;
            rvReport.ShowFindControls = false;

           
            Microsoft.Reporting.WebForms.ReportParameter[] RptParam = new Microsoft.Reporting.WebForms.ReportParameter[2];     

            RptParam[0] = new Microsoft.Reporting.WebForms.ReportParameter("Param1", ddlPara1.Text.ToString());
            RptParam[1] = new Microsoft.Reporting.WebForms.ReportParameter("Param2", txtPara2.Text.ToString());
           
            this.rvReport.ServerReport.SetParameters(RptParam);
            rvReport.ServerReport.Refresh();
            rvReport.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

on btnShowReport Click call above function Report() and see how it works
cheers,
ved

Comments