title: How to Print the data in a label using ASP.net?
body: <p>In my asp.net website i need to print the information that are inside a label. The information inside the label would be derived from the database. 
  The label would consist of data such as the customer name, address, telephone number etc.
  I need this to be printed on a sheet of paper.</p>
  
  <p>On my webpage i have a button and a HTML table. The HTML table consist of the the customers information. Everything works fine for me. I can get the print. But i would like to get the data on the print page formatted. Ex. center aligned, with some fonts and font sizes. Im not able to do so.</p>
  
  <p>The following is my print preview page<img src="https://i.stack.imgur.com/LXrNn.png" alt="enter image description here"></p>
  
  <p>and this my print page
  <img src="https://i.stack.imgur.com/KHfhM.png" alt="enter image description here"></p>
  
  <p>Its good. But i would like to get the print page a little more stylish with any logos. The size of the text needs to be increased, the table should be rather centered. It would be good if i can get a border for the table in the print page. Basically i would like to do some styles in the print page.</p>
  
  <p>i tried implementing the printstyles css but im unable to get any results. </p>
  
  <p>The code im using during the button click event of the "Print" button is</p>
  
  <pre><code>protected void btnPrint_Click(object sender, EventArgs e)
  {
  
      StringWriter sw = new StringWriter();
      HtmlTextWriter hw = new HtmlTextWriter(sw);
      StringBuilder sb = new StringBuilder();
      sb.Append("&lt;script type = 'text/javascript'&gt;");
      sb.Append("window.onload = new function(){");
      sb.Append("var divToPrint=document.getElementById('print');");
      sb.Append("var printWin = window.open('', '', 'left=0");
      sb.Append(",top=0,width=800,height=600,status=0');");
      //sb.Append("printWin.document.write(&lt;link rel='stylesheet' type='text/css' href='PrintStyle.css' media='print'/&gt;\n);");
      sb.Append("printWin.document.write(divToPrint.outerHTML);");
      sb.Append("printWin.document.close();");
      sb.Append("printWin.focus();");
      sb.Append("printWin.print();}");
      sb.Append("&lt;/script&gt;");
      ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
  
  }
  </code></pre>
  
  <p>It would be nice if someone can help me do this.</p>