如何使用C#在ASP.NET中打印Crystal Reports [英] How to print Crystal Reports in ASP.NET using C#

查看:66
本文介绍了如何使用C#在ASP.NET中打印Crystal Reports的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web项目,它有三个不同的Web表单,上面有文本框,带有提交按钮和打印按钮。我还在Crystal Reports 2013程序中创建了一个报告。我已将报告添加到Web项目中。我还在其上添加了三个带有CrystalReportViewer的Web表单。我想要做的是在Web表单上设置提交数据的打印按钮,这样它就可以打印报告而无需打印预览。那么,如何设置打印按钮以从Crystal Report Viewer打印Crystal Report?



这是带有打印按钮的网络表单。我将为此表单显示两个代码。

这是.ASPX页面代码:

I have a web project that has three different web forms that has textboxes on them with a submit button and a print button. I also created a report in Crystal Reports 2013 program. I have added the report to the web project. I also added three more web forms with CrystalReportViewer on them. What I want to do is to setup the print button on the web form that the data is submitted on so it can print out the report without a print preview. So, How can I setup the print button to print out the Crystal Report from Crystal Report Viewer?

This is the web form with the print button. I will show two codes for this form.
This is the .ASPX page code:

<%@ Page Language="C#" AutoEventWireup="True" Inherits="FinancialProfileFormA" Codebehind="FinancialProfileFormA.aspx.cs" %>

<!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></title>
    <style type="text/css">
        .style1
        {
            font-size: x-large;
            text-align: center;
        }
        .style2
        {
            width: 100%;
        }
        .style5
        {
            width: 20px;
        }
        .style7
        {
            width: 495px;
            font-weight: bold;
        }
        .style9
        {
            width: 20px;
            height: 23px;
        }
        .style10
        {
            width: 495px;
            height: 23px;
            font-weight: bold;
        }
        .style11
        {
            height: 23px;
        }
        .style18
        {
            font-weight: bold;
        }
        .style19
        {
            width: 905px;
            text-align: center;
        }
        .style21
        {
            width: 212px;
            font-weight: bold;
        }
        .style22
        {
            width: 212px;
            height: 23px;
            font-weight: bold;
        }
        .style23
        {
            font-size: small;
        }
        .style24
        {
            font-size: small;
            font-weight: normal;
        }
        .newStyle1
        {
        }
        .style3
        {
            width: 100%;
        }
        .style35
        {
            width: 469px;
            font-weight: bold;
            font-size: large;
        }
        .style36
        {
            width: 469px;
        }
        .style37
        {
            font-size: large;
            width: 424px;
        }
        .style38
        {
            font-size: x-large;
            width: 147px;
        }
        .style40
        {
            width: 645px;
            height: 23px;
            text-align: right;
        }
        .style42
        {
            height: 23px;
            width: 190px;
        }
        .style47
        {
            font-size: large;
            text-align: center;
        }
        .style48
        {
            font-size: xx-large;
        }
        .style49
        {
            font-size: x-large;
        }
        .style50
        {
            width: 585px;
            height: 137px;
        }
        .style51
        {
            font-weight: bold;
            font-size: x-large;
            text-align: center;
        }
        .style52
        {
            width: 670px;
        }
        .style53
        {
            width: 495px;
        }
        .style54
        {
            width: 212px;
        }
        .style55
        {
            font-size: x-large;
            width: 212px;
            text-align: center;
        }
        .style56
        {
            font-weight: bold;
            font-size: large;
            text-align: center;
        }
        .style57
        {
            width: 147px;
        }
    </style>
    <script language="javascript" type="text/javascript">
// <![CDATA[

        function Reset1_onclick() {

        }

// 
    </script>
</head>
<body background="Images/bkg-blu.jpg" bgcolor="#3399ff">
    <form id="form1"  runat="server">
    <div class="style1">
    <asp:Panel ID="Panel1" runat="server">
        <div style="text-align: left">
              <table 

                class="style2">
                <tr>
                    <td style="text-align: center">
                        <img class="style50" src="Images/buildout_header.jpg" /></td>
                </tr>
            </table>
                                     
        </div>
    </asp:Panel>
        
        <span class="style48">
        <br />
        Financial Profile </span></div>
    <br />
                
    <asp:TextBox ID="TextBoxINST_ID" runat="server" Enabled="False" ReadOnly="True" 

        Visible="False"></asp:TextBox>
                
    <asp:TextBox ID="TextBoxaccessLevel" runat="server" style="text-align: center" 

        Visible="False"></asp:TextBox>
                
    <br />
    <table class="style2">
        <tr>
            <td style="text-align: center">
                <asp:Label ID="lblSchool" runat="server" CssClass="style51"></asp:Label>
            </td>
        </tr>
    </table>
    <table class="style2">
        <tr>
            <td class="style52" style="text-align: right">
                <asp:Label ID="lblCity" runat="server" CssClass="style56"></asp:Label>
                ,</td>
            <td>
 <asp:Label ID="lblState" runat="server" CssClass="style56"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="style52" style="text-align: right">
                 </td>
            <td style="text-align: right">
                <asp:Label ID="lblDate" runat="server" style="font-weight: 700" 

                    Text="Today's Date"></asp:Label>
 
                <asp:TextBox ID="TextBoxDATE" runat="server" 

                    style="font-weight: 700; text-align: center" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style52" style="text-align: right">
                 </td>
            <td style="text-align: right">
                <asp:Label ID="lblTime" runat="server" style="font-weight: 700"></asp:Label>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <table class="style2">
        <tr>
            <td class="style5">
                 </td>
            <td class="style53">
                 </td>
            <td class="style55">
                <asp:Label ID="lblLYEAR" runat="server" style="font-weight: 700"></asp:Label>
            </td>
            <td>
                <span class="style49">           
                <asp:Label ID="lblYEAR" runat="server" style="text-align: center">2013</asp:Label>
                </span></td>
        </tr>
        <tr>
            <td class="style5">
                 </td>
            <td class="style53">
                                            Total Revenues and Other Additions <span class="style23">(IPEDS 
                Part B, Line 25)</span></td>
            <td class="style54">
                <asp:TextBox ID="TextBoxLYTROA" runat="server" style="text-align: left" 

                    Width="180px" ToolTip="IPEDS Part B, line 25" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
                </td>
            <td>
                <asp:TextBox ID="TextBoxTROA" runat="server" style="text-align: left" 

                    Width="180px" ToolTip="IPEDS Part B, line 25">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator16" runat="server" 

                    ControlToValidate="TextBoxTROA" 

                    ErrorMessage="Please Enter Total Revenues and Other Additions" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
                </td>
        </tr>
    </table>
    <br />
    <table class="style2">
        <tr>
            <td class="style5">
                1</td>
            <td class="style7">
                Instruction <span class="style24">(IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYInstr" runat="server" Enabled="False" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxInstr" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 01, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator17" runat="server" 

                    ControlToValidate="TextBoxInstr" ErrorMessage="You Must Enter Instruction!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style9">
                2</td>
            <td class="style10">
                Research <span class="style24">(IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style22">
                <asp:TextBox ID="TextBoxLYRes" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td class="style11">
                <asp:TextBox ID="TextBoxRes" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 02, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator19" runat="server" 

                    ControlToValidate="TextBoxRes" ErrorMessage="You Must Enter Research!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                3</td>
            <td class="style7">
                Public Service<span class="style24"> (IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYPubS" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxPubS" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 03, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator20" runat="server" 

                    ControlToValidate="TextBoxPubS" ErrorMessage="You Must Enter Public Service!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                4</td>
            <td class="style7">
                Academic Support<span class="style24"> (IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYAcad" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxAcad" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 05, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator21" runat="server" 

                    ControlToValidate="TextBoxAcad" 

                    ErrorMessage="You Must Enter Academic Support!!!" ForeColor="Red" 

                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                5</td>
            <td class="style7">
                Student Services <span class="style24">(IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYStudS" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxStudS" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 06, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator22" runat="server" 

                    ControlToValidate="TextBoxStudS" 

                    ErrorMessage="You Must Enter Student Services!!!" ForeColor="Red" 

                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                6</td>
            <td class="style7">
                Institutional Support<span class="style24"> (IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYInstiS" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxInstiS" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 07, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator23" runat="server" 

                    ControlToValidate="TextBoxInstiS" 

                    ErrorMessage="You Must Enter Institutional Support!!!" ForeColor="Red" 

                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                7</td>
            <td class="style7">
                Operation & Maintenance of Plant <span class="style24">(IPEDS Part C, Line 
                01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYOperM" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxOperM" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 08, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator24" runat="server" 

                    ControlToValidate="TextBoxOperM" 

                    ErrorMessage="You Must Enter Operation & Maintenance of Plant!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                8</td>
            <td class="style7">
                Scholarships & Fellowships, Excluding Discounts & Allowances
                <span class="style24">(IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYSFEDA" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxSFEDA" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 10, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator25" runat="server" 

                    ControlToValidate="TextBoxSFEDA" 

                    ErrorMessage="You Must Enter Scholarships & Fellowships!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                9</td>
            <td class="style7">
                Auxiliary Enterprises <span class="style24">(IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYAuxE" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxAuxE" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 11, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator26" runat="server" 

                    ControlToValidate="TextBoxAuxE" 

                    ErrorMessage="You Must Enter Auxiliary Enterprises!!!" ForeColor="Red" 

                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                10</td>
            <td class="style7">
                Hospital Services <span class="style24">(IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYHosS" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxHosS" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 12, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator27" runat="server" 

                    ControlToValidate="TextBoxHosS" 

                    ErrorMessage="You Must Enter Hospital Services!!!" ForeColor="Red" 

                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                11</td>
            <td class="style7">
                Independent Operations <span class="style24">(IPEDS Part C, Line 01, Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYIndeO" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxIndeO" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 13, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator28" runat="server" 

                    ControlToValidate="TextBoxIndeO" 

                    ErrorMessage="You Must Enter Independent Operations!!!" ForeColor="Red" 

                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style5">
                12</td>
            <td class="style7">
                Other Expenses & Deductions <span class="style24">(IPEDS Part C, Line 01, 
                Column 01)</span></td>
            <td class="style21">
                <asp:TextBox ID="TextBoxLYOED" runat="server" Enabled="False" ReadOnly="True" 

                    Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:TextBox ID="TextBoxOED" runat="server" Width="180px" 

                    ToolTip="IPEDS Part C, Line 14, Column 01">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator29" runat="server" 

                    ControlToValidate="TextBoxOED" 

                    ErrorMessage="You Must Enter Other Expenses & Deductions!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        </table>
    <br />
    <br />
    <table class="style2">
        <tr>
            <td class="style47">
                                          <span 

                    class="style49"> 
                Financial Indicators</span></td>
        </tr>
    </table>
    <br />
    <table class="style3">
        <tr>
            <td class="style37">
                 </td>
            <td class="style38">
                     <asp:Label ID="lblLYEAR2" runat="server"></asp:Label>
                </td>
            <td class="style35">
                           
                <asp:Label ID="lblYEAR2" runat="server">2013</asp:Label>
                </td>
        </tr>
        <tr>
            <td class="style37">
                 </td>
            <td class="style57">
                 </td>
            <td class="style36">
                 </td>
        </tr>
        <tr>
            <td class="style37">
                Total Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTA" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator30" runat="server" 

                    ControlToValidate="TextBoxTA" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Total Liabilities</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTL" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTL" runat="server" Width="180px" AutoPostBack="True" 

                    ontextchanged="TextBoxTL_TextChanged">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator31" runat="server" 

                    ControlToValidate="TextBoxTL" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Total Net Assets</td>
            <td class="style57">
                 </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTNA" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Nonexpendable/Permanently Restricted Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYNPRNA" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxNPRNA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator32" runat="server" 

                    ControlToValidate="TextBoxNPRNA" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Expendable/Temporarily Restricted Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYETRNA" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxETRNA" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator33" runat="server" 

                    ControlToValidate="TextBoxETRNA" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Total Unrestricted Net Assets <span class="style23">(Unrestricted net assets 
                Plus capital assets, net)</span></td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTUNA" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTUNA" runat="server" Width="180px" AutoPostBack="True" 

                    ontextchanged="TextBoxTUNA_TextChanged">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator34" runat="server" 

                    ControlToValidate="TextBoxTUNA" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Total Revenue</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTR" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTR" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator35" runat="server" 

                    ControlToValidate="TextBoxTR" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Tuition and Fees, Net</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTFN" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTFN" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator36" runat="server" 

                    ControlToValidate="TextBoxTFN" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Current Debt</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYCD" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxCD" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator37" runat="server" 

                    ControlToValidate="TextBoxCD" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Long-term Debt</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYLTD" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxLTD" runat="server" Width="180px">0</asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator38" runat="server" 

                    ControlToValidate="TextBoxLTD" 

                    ErrorMessage="You Must Enter A Number For This Field!!!" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style37">
                Total Net Assets</td>
            <td class="style57">
                <asp:TextBox ID="TextBoxLYTNA" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
            </td>
            <td class="style36">
                <asp:TextBox ID="TextBoxTNA2" runat="server" Width="180px" Enabled="False" 

                    ReadOnly="True"></asp:TextBox>
                <asp:CompareValidator ID="CompareValidator1" runat="server" 

                    ControlToCompare="TextBoxTNA" ControlToValidate="TextBoxTNA2" 

                    ErrorMessage="The Entry Does Not Match Each Other!!" ForeColor="Red"></asp:CompareValidator>
            </td>
        </tr>
    </table>
    <br />
    <table class="style3">
        <tr>
            <td class="style40">
                Name</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxFullN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 

                    ControlToValidate="TextBoxFullN" ErrorMessage="Please Give Your Full Name!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                Title</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxTitle" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 

                    ControlToValidate="TextBoxTitle" ErrorMessage="Please Give Your Title!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                Institution</td>
            <td class="style42">
                <asp:Label ID="lblSchool2" runat="server"></asp:Label>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style40">
                Mailing Address</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxMA" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 

                    ControlToValidate="TextBoxMA" 

                    ErrorMessage="Please Give Your Mailing Address!!!" ForeColor="Red" 

                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                Telephone Number</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxTN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 

                    ControlToValidate="TextBoxTN" 

                    ErrorMessage="Please Give Your Telephone Number!!!" ForeColor="Red" 

                    CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                Fax Number</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxFN" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" 

                    ControlToValidate="TextBoxFN" ErrorMessage="Please Give Your  Fax Number!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style40">
                Email Address</td>
            <td class="style42">
                <asp:TextBox ID="TextBoxEA" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" 

                    ControlToValidate="TextBoxEA" ErrorMessage="Please Give Your Email Address!!!" 

                    ForeColor="Red" CssClass="style18"></asp:RequiredFieldValidator>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <table class="style2">
        <tr>
            <td class="style19">
                                                                
                <asp:Button ID="ButtonSubmit" runat="server" onclick="ButtonSubmit_Click" 

                    Text="Submit" Width="100px" style="text-align: center" />
            </td>
            <td>
                <asp:Button ID="ButtonPrint" runat="server" onclick="ButtonPrint_Click" Text="Print" Width="100px" />
            </td>
        </tr>
    </table>
    </form>
    </body>
</html>





This is the Behind code for that page:



This is the Behind code for that page:

using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Drawing.Printing;
using System.IO;
using System.Web.SessionState;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class FinancialProfileFormA : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
     TextBoxINST_ID.Text = Session["inst_id"].ToString();
    }
protected void ButtonSubmit_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("Insert into Table22 (INST_ID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT, TOTALNETASSETS) values (@INST_ID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @EXPENDABLE, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT, @TOTALNETASSETS)Insert into Table23 (INST_ID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT, TOTALNETASSETS) values (@INST_ID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @EXPENDABLE, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT, @TOTALNETASSETS)", con);
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTROA.Text);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxRes.Text);
        cmd.Parameters.AddWithValue("@PUBLIC_SER", TextBoxPubS.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcad.Text);
        cmd.Parameters.AddWithValue("@STUDENT_SE", TextBoxStudS.Text);
        cmd.Parameters.AddWithValue("@INSTITUTIO", TextBoxInstiS.Text);
        cmd.Parameters.AddWithValue("@PHYSICAL_P", TextBoxOperM.Text);
        cmd.Parameters.AddWithValue("@SCHOLARSHI", TextBoxSFEDA.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@HOSPITALS", TextBoxHosS.Text);
        cmd.Parameters.AddWithValue("@INDEPENDEN", TextBoxIndeO.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxOED.Text);
        cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
        cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
        cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
        cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text);
        cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
        cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
        cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
        cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
        cmd.Parameters.AddWithValue("@LONGTERMDEBT", TextBoxLTD.Text);
        cmd.Parameters.AddWithValue("@FINYR", lblYEAR.Text);
        cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
        cmd.Parameters.AddWithValue("@TOTALNETASSETS", TextBoxTNA.Text);


        cmd.ExecuteNonQuery();
        ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You Have Successfully Submitted the Financial Profile');", true);
con.Close();

protected void ButtonPrint_Click(object sender, EventArgs e)
    {
        
    }
}





Here is the .ASPX code for the Crystal Report Viewer:



Here is the .ASPX code for the Crystal Report Viewer:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportFormA.aspx.cs" Inherits="SACSCOCLogin1._1.ReportFormA" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<!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></title>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    
        <CR:CrystalReportViewer ID="CrystalReportViewer1"  runat="server" 

            AutoDataBind="True" EnableDatabaseLogonPrompt="False" 

            GroupTreeImagesFolderUrl="" Height="1202px" 

            ReportSourceID="CrystalReportSourceA" ToolbarImagesFolderUrl="" 

            ToolPanelView="None" ToolPanelWidth="200px" Width="1104px" />
        <CR:CrystalReportSource ID="CrystalReportSourceA"  runat="server">
            <Report FileName="FormAReport.rpt">
            </Report>
        </CR:CrystalReportSource>
    
    </div>
    </form>
</body>
</html>





The Behind Code for that page:





The Behind Code for that page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace SACSCOCLogin1._1
{
    public partial class ReportFormA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CrystalReportViewer1.Visible = false;
        }
    }
}

推荐答案

You could export the report to PDF behind the scenes (i.e. through .NET code) as it’s described here but instead of using that solution, you could embed some javascript print function into the PDF file using PDFSharp (http://stackoverflow.com/a/17732531[^]) to get it printed directly when the file is opened. With this approach you avoid print preview and the printing should work with any browser.
You could export the report to PDF behind the scenes (i.e. through .NET code) as it's described here but instead of using that solution, you could embed some javascript print function into the PDF file using PDFSharp (http://stackoverflow.com/a/17732531[^]) to get it printed directly when the file is opened. With this approach you avoid print preview and the printing should work with any browser.


这篇关于如何使用C#在ASP.NET中打印Crystal Reports的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆