Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to generate report which is in the grid view format and i have to provide print button functionality to print that grid view generated data..so how can i do this??
Posted
Comments
Bh@gyesh 9-Apr-14 0:38am    
Hi,
If you are dealing with window application then you can print easily wih the use of lib.
If there ia aweb application then, you can export that grid data in PDF and from PDF you can print.

Solution: Below i will print the table using jquery/javascript:

HTML
<script src="http://code.jquery.com/jquery-latest.min.js">
        type="text/javascript"></script>

XML
<script type="text/javascript">
    function printData() {
        var divToPrint = document.getElementById("printTable");
        var newWin = window.open("");
        newWin.document.write(divToPrint.outerHTML);
        newWin.print();
        newWin.close();
    }
</script>


HTML:
XML
<table border="1" cellpadding="3" id="printTable">
    <tbody><tr>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Points</th>
    </tr>
    <tr>
        <td>Jill</td>
        <td>Smith</td>
        <td>50</td>
    </tr>
    <tr>
        <td>Eve</td>
        <td>Jackson</td>
        <td>94</td>
    </tr>
    <tr>
        <td>John</td>
        <td>Doe</td>
        <td>80</td>
    </tr>
    <tr>
        <td>Adam</td>
        <td>Johnson</td>
        <td>67</td>
    </tr>
</tbody></table>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900