Monday, June 10, 2013

Print the Data in Web Application

Using Simple Javascript:


Put a button on the page like the following:
<input type="button" value="Print" onclick="doPrint();" id="Button2">
Then add the following javascript code in the head section of the page:

<script>
        function doPrint()
        {
            var prtContent = document.getElementById('<%= GridView1.ClientID %>');
            prtContent.border = 0; //set no border here
            var WinPrint = window.open('','','letf=100,top=100,width=1000,height=1000,toolbar=0,scrollbars=1,status=0,resizable=1');
            WinPrint.document.write(prtContent.outerHTML);
            WinPrint.document.close();
            WinPrint.focus();
            WinPrint.print();
            WinPrint.close();
        }
</script>

No comments: