title: asp.net gridview printing
body: <p>i am printing a gridview in asp.net that is contained within a panel - it works in IE perfectly</p>
  
  <ol>
  <li>In Opera 12.02 it appears to be printing out my main form not the print page ? Do you know why this is. </li>
  <li>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?</li>
  </ol>
  
  <p>I'm assuming the issue is in my javascript - i can post markup if needed but hopefully that will not be required.</p>
  
  <p>thanks
  Damo
  <strong>javascript</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          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 &gt; 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() &gt;= 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('&lt;' + 'html' + '&gt;&lt;head&gt;&lt;link href="assets/css/Print.css" rel="stylesheet" type="text/css" /&gt;&lt;title&gt;' + AuditPrintDetailEverypage + '&lt;/title&gt; &lt;/head&gt;&lt;' + 'body  style="background:none !important"' + '&gt;');
                          WinPrint.document.write(printContent.innerHTML);
                          WinPrint.document.write('          ' + AuditPrintDetailLastPage);
                          WinPrint.document.write('&lt;' + '/body' + '&gt;&lt;' + '/html' + '&gt;');
                          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 &gt;= 0 &amp;&amp; num &lt; 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;
              }
          }
      &lt;/script&gt;
  </code></pre>