How TO Print Specific table from a webpage? RRS feed

  • Question

  • User902236755 posted

    First you have to create a webpage and table that has to be print 

    <table id="myt"  width = "100%" border ="2" frame ="box" rules ="all"  cellpadding ="2">

    set the ID= "SomeID" , "myt" in my case

    a little java script 

     <script language="javascript" type ="text/javascript" >
        function printTbl() {
            var TableToPrint = document.getElementById('myt');
            newWin = window.open("");

    Create a button to print this table 

    <asp:Button ID="Button1" runat="server"    OnClientClick  ="printTbl()"   />

    "OnClientClick" call that javascript function "printTbl()"

    Thats it...... Happy Coding............ Smile

    Friday, June 21, 2013 7:03 AM

All replies

  • User309602797 posted

    place your table inside <div> tag and try to print div 

    <div id="divId">

    <table id="myt" width = "100%" border ="2" frame ="box" rules ="all" cellpadding ="2">


    <script language="javascript" type="text/javascript">
        function PrintRadGrid(divId) {
            var divToPrint = document.getElementById(divId);
            var newWin = window.open('PrintDiv', 'Print-Window', 'width=920,height=750,top=100,left=100');
            newWin.document.write('<html><title>Invitation Status</title><head><style>#in {display:none}</style><body   onload="window.print()">' + divToPrint.innerHTML + '</body></html>');
            setTimeout(function () { newWin.close(); }, 10);

    Hope it helps you ...

    Friday, June 21, 2013 8:16 AM
  • User902236755 posted

    Thanks for reply 


    i was just posted an article ... it works fine for me so i thought i must share it on this forum as it may be helpful for others. any ways thanks again for posting it will give another idea to people. Tongue Out

    Sunday, June 23, 2013 8:40 AM
  • User-473986174 posted

    this code is not print div with css it is printing unformat .i have apply inline css. please tell me solution which print with css. 

    Friday, January 9, 2015 1:53 AM