Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
code in a page should show report

C#
dt.TableName = "Table";
              Session["ReportData"] = dt;
              dt.AcceptChanges();
              int reportheight = 1200;
              string script = "window.open(\"../Reports/Report.aspx?name=rptNhapThietBi\",\"Phiếu nhập\",\"width=screen.width, height=" + reportheight + "\")";
              ScriptManager.RegisterStartupScript(this, GetType(), "rptNhapThietBi", script, true);


Illustration
HTML
<a href="http://imgur.com/WtkZkDS"><img src="http://i.imgur.com/WtkZkDS.png" title="source: imgur.com" /></a>

[img]http://i.imgur.com/WtkZkDS.png[/img]

Code in ReportPage
ASP.NET
<body>
    <script type="text/javascript">
        function btnprint_Click() {
            var dvReport = document.getElementById("DivRePort");
            var frame1 = dvReport.getElementsByTagName("iframe")[0];
            if (navigator.appName.indexOf("Internet Explorer") != -1) {
                frame1.name = frame1.id;
                window.frames[frame1.id].focus();
                window.frames[frame1.id].print();
            }
            else {
                var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
                frameDoc.print();
            }
        }
        window.onbeforeunload = function () { myUnloadEvent(); }
        function myUnloadEvent() {
            alert('Calling some alert messages here');
            //even you can call some functions that will terminater the DB connections or something similar.
        }
    </script>
    <form id="form1" runat="server">
        <table style="width: 100%; height: 29px;">
            <tr>
                <td style="width: 40px; height: 23px;">
                    <dx:ASPxButton ID="ASPxButton1" runat="server" Text="In" AutoPostBack="false">
                    </dx:ASPxButton>
                </td>
            </tr>
        </table>
        <div style="overflow: auto" id="DivRePort">
            <dx:ASPxSplitter ID="ASPxSplitter2" runat="server" Height="600px">
                <Panes>
                    <dx:SplitterPane ScrollBars="Auto">
                        <ContentCollection>
                            <dx:SplitterContentControl runat="server">
                                <CR:CrystalReportViewer ID="CrystalReportViewer" runat="server" AutoDataBind="True" ToolPanelView="None" ToolPanelWidth="900px" PrintMode="ActiveX" />
                            </dx:SplitterContentControl>
                        </ContentCollection>
                    </dx:SplitterPane>
                    <dx:SplitterPane Visible="False">
                        <ContentCollection>
                            <dx:SplitterContentControl runat="server"></dx:SplitterContentControl>
                        </ContentCollection>
                    </dx:SplitterPane>
                </Panes>
            </dx:ASPxSplitter>
        </div>
    </form>
</body>

C#
string reportname = Request.QueryString["name"] + ".rpt";
            if (Session["ReportData"] != null)
            {
                reportdocument = new ReportDocument();
                string filepath = Server.MapPath(reportname);
                reportdocument.Load(filepath);
                reportdocument.SetDataSource(Session["ReportData"]);
                DataTable dt = new DataTable();
                dt = (DataTable)Session["ReportData"];
                CrystalReportViewer.ReportSource = reportdocument;
                CrystalReportViewer.DataBind();
            }

C#
but when you run it does not contest

HTML
<a href="http://imgur.com/s88cxag"><img src="http://i.imgur.com/s88cxag.png" title="source: imgur.com" /></a>

[img]http://i.imgur.com/s88cxag.png[/img]
Posted
Comments
Sinisa Hajnal 13-Jan-16 2:32am    
Did you check that your Session contains the data at the moment of the binding?
Member 12235220 13-Jan-16 20:47pm    
My problem report is not loaded on the site

1 solution

This link can help you out.

http://www.c-sharpcorner.com/UploadFile/rahul4_saxena/create-crystal-report-in-Asp-Net
 
Share this answer
 
Comments
Member 12235220 13-Jan-16 20:58pm    
I've tried it, but the result remains unchanged

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900