簡體   English   中英

使用C#打印整個aspx頁面

[英]To print entire aspx page using C#

我創建了一個包含標簽網格等的asp.net頁面。

碼:

<%@ Page Title="" Language="C#" MasterPageFile="~/App/MasterPage.master"  AutoEventWireup="true" CodeFile="ServiceCheckList.aspx.cs" Inherits="App_AutoRx_ServiceCheckList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="Server">
    <div class="container">
        <div class="row" style="box-shadow: 0px 1px 6px #808080 !important;">
            <div class="panel">
                <div class="panel-heading">
                    <h3 style="color: black;">Service Check List</h3>

                    <div style="text-align: right">
                        Date :
                        <asp:Label ID="lblDate" runat="server"></asp:Label>
                    </div>
                </div>
                <div class="panel-body">
                    <div>
                        Service Check List Code :
                        <asp:Label ID="lblSCLC" runat="server" Text="CSSC"></asp:Label>
                    </div>
                    <table id="tblbase" class="nav-justified" border="1" style="border: thin inset #999999">
                        <tr style="text-align: center; font-size: medium; color: #000000;">
                            <td style="width: 35%; background-color: red; color: white">Customer Details</td>
                            <td style="width: 65%; background-color: red; color: white">Vehicle Details</td>
                        </tr>
                        <tr>
                            <td>
                                <div class="panel-body">
                                    <table id="tblCustomer" class="nav-justified" style="column-width: inherit">
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblForCustomerName" runat="server" Text="Customer Name:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblCustomerName" runat="server" Text="Suraj"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblForContactNo" runat="server" Text="Contact No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblContactNo" runat="server" Text="123456"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblForAlternateNo" runat="server" Text="Alternate No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblAlternateNo" runat="server" Text="scc-101"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforEmailId" runat="server" Text="Email Id:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblEmailId" runat="server" Text="scc-101"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforAddress" runat="server" Text="Address:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblAddress"  runat="server" Text="scc-101"></asp:Label></td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                            <td>
                                <div class="panel-body">
                                    <table id="tblvehicle" class="nav-justified" style="column-width: inherit">
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforRegistrationNo" runat="server" Text="Registration No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblRegistrationNo" runat="server" Text="XYZ"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblforVIN" runat="server" Text="VIN No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblVIN" runat="server" Text="XYZ"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforManufacturer" runat="server" Text="Manufacturer Name:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblManufacturer" runat="server" Text="123456"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblforModel" runat="server" Text="Model Name:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblModel" runat="server" Text="123456"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforFuelType" runat="server" Text="Fuel Type:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblFuelType" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblforEnginesize" runat="server" Text="Engine Size:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblEnginesize" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforEngineNo" runat="server" Text="Engine No:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblEngineNo" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblforcolor" runat="server" Text="Color:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblcolor" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Label ID="lblforYearBuild" runat="server" Text="Year of build:"></asp:Label></td>
                                            <td>
                                                <asp:Label ID="lblYearBuild" runat="server" Text="scc-uefuvfu"></asp:Label></td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="panel-body">
                    <div class="heading">
                        <h4>Items Details</h4>
                    </div>
                    <table id="tblItems" class="nav-justified" border="1" style="border: thin inset #999999">
                        <tr style="text-align: center; font-size: medium; color: #000000;">
                            <td style="width: 33%; background-color: red; color: white">Services</td>
                            <td style="width: 33%; background-color: red; color: white">Spare Parts</td>
                            <td style="width: 33%; background-color: red; color: white">Tachnician </td>
                        </tr>
                        <tr>
                            <td style="width: 33%">
                                <asp:GridView ID="gvServices" runat="server"></asp:GridView>
                            </td>
                            <td style="width: 33%">
                                <asp:GridView ID="gvSpare" runat="server"></asp:GridView>

                            </td>
                            <td style="width: 33%">
                                <asp:GridView ID="gvTech" runat="server"></asp:GridView>

                            </td>
                        </tr>
                    </table>
                </div>
                <div class="panel-body">
                    <div class="heading">
                        <h4>Office Use Only</h4>
                    </div>
                    <table class="nav-justified" border="1" style="border: thin inset #999999">
                        <tr style="text-align: center; font-size: medium; color: #000000;">
                            <td style="width: 100%; background-color: red; color: white">Office Use</td>

                        </tr>
                        <tr style="text-align:justify; font-size: medium; color: #000000;">
                            <td style="width: 100%">
                                <div>
                                    uiuiht8d7yjgnjgixtixjtn
                                </div>
                            </td>
                        </tr>
                        <tr style="text-align: center; font-size: medium; color: #000000;">
                            <td style="width: 100%">
                                <div style="text-align: left">
                                    Address :
                                    <asp:Label ID="lblOfficeAddress" runat="server" Text="office adress"></asp:Label>
                                </div>

                            </td>

                        </tr>
                    </table>

                </div>
                <div class="panel-body">
                    <p style="text-align: justify">I hereby authorize the above repair work to be done along with the necessary material, and hereby grant you and/or your empoyees permission to operate the car, truck or vechicle herein described on streets, highways or elsewhere for the purpose of testing and/or inspection. An express mechanic's lien is hereby acknowledged on above car, truck or vehicle to secure the amount of repair thereto.</p>
                    <div>

                        <table class="nav-justified" style="color: black; font-size: medium;">
                            <tr>
                                <td>Work Authorized By:____________________</td>
                                <td style="text-align: right">Date Promised:
                                    <asp:Label ID="lblDatePromised" runat="server" Text="x/xx/2222"></asp:Label></td>
                            </tr>
                            <tr>
                                <td>Delivered To:____________________</td>
                                <td style="text-align: right">Date Delivered:
                                    <asp:Label ID="lblDateDelivered" runat="server" Text="x/xx/2222"></asp:Label></td>
                            </tr>
                        </table>

                    </div>
                </div>
            </div>
        </div>
        <asp:LinkButton ID="LinkButton1"  runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
    </div>


</asp:Content>

我想打印此頁面,但是當我使用window.print();時。 它提供了一些不同的o / p,它不包括css效果以及來自master的頁眉和頁腳也不是格式...謝謝...。

預期輸出 在此處輸入圖片說明

越來越 在此處輸入圖片說明

您必須通過“ CSS Media querys”在CSS中定義打印布局

例如

@media print {
    p { font-weight: bold; }
}

如果在打印頁面時需要自定義布局。

或者,您可以定義一個特殊的css文件進行這樣的打印

<link rel="stylesheet" type="text/css" href="print.css" media="print">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM