Here is my aspx page where I have two div of which I want to print 1st div.
Here is the trick with small javascript
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="PrintDivContent.aspx.vb" Inherits="Default2" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>Untitled Page</title>
  6. <script language="javascript" type="text/javascript">
  7. function printDiv(divID) {
  8. //Get the HTML of div
  9. var divElements = document.getElementById(divID).innerHTML;
  10. //Get the HTML of whole page
  11. var oldPage = document.body.innerHTML;
  12. //Reset the page's HTML with div's HTML only
  13. document.body.innerHTML = "<html><head><title></title></head><body>" + divElements + "</body>";
  14. //Print Page
  15. window.print();
  16. //Restore orignal HTML
  17. document.body.innerHTML = oldPage;
  18. //disable postback on print button
  19. return false;
  20. }
  21. </script>
  22. </head>
  23. <body>
  24. <form id="form1" runat="server">
  25. <div id="printablediv" style="width: 100%; background-color: Blue; height: 200px">
  26. Print me I am in 1st Div
  27. </div>
  28. <div id="donotprintdiv" style="width: 100%; background-color: Gray; height: 200px">
  29. I am not going to print
  30. </div>
  31. <input type="button" value="Print 1st Div" onclick="javascript:printDiv('printablediv')" />
  32. </form>
  33. </body>
  34. </html>
Please Reply if you have any query