Tuesday, January 7, 2014

How to Print Data Using JavaScript.

Here I am going to explain ,How to print data using JavaScript.
I use a panel control to print the particular panel and I put many controls like
GridView, Label, Text etc.

Demo :


JavaScript For Print Data :
Copy and Paste the Below Code Before </head>

<script type="text/javascript">
    function PrintPanel() {
        var prtpanel = document.getElementById('<%=Panel1.ClientID %>');

        prtpanel.border = 0;
        var prtwin = window.open('', 'PrintGridViewData', 'left=400,top=100,width=1200,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1,align=centre');
        prtwin.document.write("Easy Dot Net Coding Print Screen", "", prtpanel.outerHTML);
        prtwin.document.close();
        prtwin.focus();

        prtwin.print();
        prtwin.close();
    }
 </script>

Now add a Button  and Panel Control in .aspx page  like the Below Code

 <input type="button" id="btnPrint" value="Print" onclick="PrintPanel()"   />  

<asp:Panel ID="Panel1" runat="server">
    WelCome To Easy Dot Net Coding.

    </asp:Panel>


If this code help you ,please share.

No comments:

Post a Comment