简体   繁体   English

asp.net gridview打印

[英]asp.net gridview printing

i am printing a gridview in asp.net that is contained within a panel - it works in IE perfectly 我在面板中包含的asp.net中打印gridview-完美在IE中工作

  1. In Opera 12.02 it appears to be printing out my main form not the print page ? 在Opera 12.02中,它似乎是在打印我的主要表单而不是打印页面? Do you know why this is. 你知道为什么吗
  2. In Mozilla firefox 16.0.2 it only loads one page in the print preview and prints that one page? 在Mozilla firefox 16.0.2中,它仅在打印预览中加载一页并打印那一页? Do you know why this is? 你知道为什么吗

I'm assuming the issue is in my javascript - i can post markup if needed but hopefully that will not be required. 我假设问题出在我的JavaScript中-如果需要,我可以发布标记,但希望这不是必需的。

thanks Damo 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(); should be window.onload = window.print; 应该是window.onload = window.print; Also my css had overflow: hidden; 我的CSS也溢出了:隐藏; which opera and mozilla dont like so i removed these 哪个歌剧和mozilla不喜欢,所以我删除了这些

now its working ok thanks damo 现在可以了,谢谢damo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM