title: How can I print a full gridview area via a custom print window?
body: <p>I'm in the process of creating a custom GridView data Print window that is designed to just print out the gridview area. One button will print out the grid view for the current window and the other button for all the records in the GridView.  As the code stands now, when the button is clicked (Printing the current page and all of the records respectively) the preview window shows all the records in the GridView perfectly (23 columns including two command fields on either side of the GridView).  However, when the job is printed out the grid view is chopped (only shows about half of the grid) no matter what printer or CSS/Formatting settings I tweak. </p>
  
  <p>The two challenges I'm encountering is that 1) I am unable to print the full gridview in portrait or landscape and 2) my javascript is pretty weak.  How can I tweak the following code so that when the gridview prints, the FULL grid is printed?  </p>
  
  <p>If more information is needed, please do not hesitate to ask.</p>
  
  <p>Here is the code I have behind my aspx file for the print buttons.</p>
  
  <pre><code>protected void PrintCurrentPage_Click(object sender, EventArgs e)
  {
  GridView1.PagerSettings.Visible = false;
  GridView1.DataBind();
  StringWriter sw = new StringWriter();
  HtmlTextWriter hw = new HtmlTextWriter(sw);
  GridView1.RenderControl(hw);
  string gridHTML = sw.ToString().Replace("\"", "'")
  .Replace(System.Environment.NewLine, "");
  StringBuilder sb = new StringBuilder();
  sb.Append("&lt;script type = 'text/javascript'&gt;");
  sb.Append("window.onload = new function(){");
  sb.Append("var printWin = window.open('', '', 'left=0");
  sb.Append(",top=0,width=3000,height=600,status=0');");
  sb.Append("printWin.document.write(\"");
  sb.Append(gridHTML);
  sb.Append("\");");
  sb.Append("printWin.document.close();");
  sb.Append("printWin.focus();");
  sb.Append("printWin.print();");
  sb.Append("printWin.close();};");
  sb.Append("&lt;/script&gt;");
  ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
  GridView1.PagerSettings.Visible = true;
  GridView1.DataBind();
  
  }
  </code></pre>
  
  <p>And here is the code for printing all the records.</p>
  
  <pre><code>protected void PrintAll_Click(object sender, EventArgs e)
  {
  GridView1.AllowPaging = false;
  GridView1.DataBind();
  StringWriter sw = new StringWriter();
  HtmlTextWriter hw = new HtmlTextWriter(sw);
  GridView1.RenderControl(hw);
  string gridHTML = sw.ToString().Replace("\"", "'")
      .Replace(System.Environment.NewLine, "");
  StringBuilder sb = new StringBuilder();
  sb.Append("&lt;script type = 'text/javascript'&gt;");
  sb.Append("window.onload = new function(){");
  sb.Append("var printWin = window.open('', '', 'left=0");
  sb.Append(",top=0,width=3000,height=600,status=0');");
  sb.Append("printWin.document.write(\"");
  sb.Append(gridHTML);
  sb.Append("\");");
  sb.Append("printWin.document.close();");
  sb.Append("printWin.focus();");
  sb.Append("printWin.print();");
  sb.Append("printWin.close();};");
  sb.Append("&lt;/script&gt;");
  ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
  GridView1.AllowPaging = true;
  GridView1.DataBind();
  
  
  }
  </code></pre>