简体   繁体   中英

asp.net gridview printing

i am printing a gridview in asp.net that is contained within a panel - it works in IE perfectly

  1. In Opera 12.02 it appears to be printing out my main form not the print page ? 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? 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.

thanks Damo 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(); should be window.onload = window.print; Also my css had overflow: hidden; which opera and mozilla dont like so i removed these

now its working ok thanks damo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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