簡體   English   中英

asp.net gridview打印

[英]asp.net gridview printing

我在面板中包含的asp.net中打印gridview-完美在IE中工作

  1. 在Opera 12.02中,它似乎是在打印我的主要表單而不是打印頁面? 你知道為什么嗎
  2. 在Mozilla firefox 16.0.2中,它僅在打印預覽中加載一頁並打印那一頁? 你知道為什么嗎

我假設問題出在我的JavaScript中-如果需要,我可以發布標記,但希望這不是必需的。

謝謝達莫的JavaScript

<script type="text/javascript">
        function PrintGridData(GridToPrint, PanelName) {
            try {
                var Grid = document.getElementById(GridToPrint);
                var printContent = document.getElementById(PanelName);
                //alert(printContent);
                if (Grid)  // See if the Grid Exists First
                {

                    if (Grid.rows.length > 0) { // See if the Grid contains any rows
                        var windowUrl = 'about:blank';
                        var UserLoggedIn = $("#lblUser").text()
                        var now = new Date();
                        var strDateTime = [[AddZero(now.getDate()), AddZero(now.getMonth() + 1), now.getFullYear()].join("/"), [AddZero(now.getHours()), AddZero(now.getMinutes())].join(":"), now.getHours() >= 12 ? "PM" : "AM"].join(" ");
                        var Database = 'ProductionDatabase';
                        var windowName = 'Report';
                        var AuditPrintDetailEverypage =  UserLoggedIn + ' Time : ' + strDateTime ;
                        var AuditPrintDetailLastPage = '      System Report ' + ' Source Database: ';
                        var WinPrint = window.open(windowUrl, windowName, 'left=300,top=300,right=500,bottom=500,width=1000,height=500');
                        WinPrint.document.write('<' + 'html' + '><head><link href="assets/css/Print.css" rel="stylesheet" type="text/css" /><title>' + AuditPrintDetailEverypage + '</title> </head><' + 'body  style="background:none !important"' + '>');
                        WinPrint.document.write(printContent.innerHTML);
                        WinPrint.document.write('          ' + AuditPrintDetailLastPage);
                        WinPrint.document.write('<' + '/body' + '><' + '/html' + '>');
                        WinPrint.document.close();
                        //alert(printContent.innerHTML);
                        //alert(WinPrint.document);
                        if (window.opera) {
                        //alert('opera browser detected')
                           window.onload = window.print();
                            //window.onload = WinPrint.print();
                            //WinPrint.close();
                        }
                        else {

                            WinPrint.focus();
                            WinPrint.print();
                            WinPrint.close();
                        }
                    }
                    else { // No Results to print 
                        document.getElementById('lblErrorCode').innerHTML = '-1';
                        document.getElementById('lblErrorMessage').innerHTML = 'You have no Results to print. Please run a report.';
                        document.getElementById('lblExMessage').innerHTML = '-1';
                        var modal = $find("modalPopupExtenderError");
                        modal.show();
                    }
                }
                else { // No Grid to print 
                    document.getElementById('lblErrorCode').innerHTML = '-1';
                    document.getElementById('lblErrorMessage').innerHTML = 'You have no Grid to print. Please run a report.';
                    document.getElementById('lblExMessage').innerHTML = '-1';
                    var modal = $find("modalPopupExtenderError");
                    modal.show();
                    return;
                }

            }
            catch (err) {
                //alert(err);
                document.getElementById('lblErrorCode').innerHTML = '-1';
                document.getElementById('lblErrorMessage').innerHTML = err;
                document.getElementById('lblExMessage').innerHTML = '-1';
                var modal = $find("modalPopupExtenderError");
                modal.show();           
                return;
            }
        }
        function AddZero(num) {
            try {
                return (num >= 0 && num < 10) ? "0" + num : num + "";
            }
            catch (err) {
                //alert(err);
                document.getElementById('lblErrorCode').innerHTML = '-1';
                document.getElementById('lblErrorMessage').innerHTML = err;
                document.getElementById('lblExMessage').innerHTML = '-1';
                var modal = $find("modalPopupExtenderError");
                modal.show();
                return;
            }
        }
    </script>

window.onload = window.print(); 應該是window.onload = window.print; 我的CSS也溢出了:隱藏; 哪個歌劇和mozilla不喜歡,所以我刪除了這些

現在可以了,謝謝damo

暫無
暫無

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

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