Print Access database records on Button click in ASP.Net

Last Reply 2 months ago By dharmendr

Posted 2 months ago

Can anybody please help in coding to print Microsoft Access Database along with some additional information in asp.net in vb on the click of a button, Please???

Posted 2 months ago

Hi ShihabKhan,

Please follow the below steps.

1. Read the data from access database and bind in GridView inside a ASP.Net Panel.

For reading data from access database refer below links.

How to connect MS Access DataBase in ASP.Net using VB.Net

jQuery AutoComplete TextBox using Microsoft Access Database in ASP.Net

2. Print ASP.Net Panel contents using JavaScript.

Print ASP.Net Panel contents with Print Preview using JavaScript


Posted 2 months ago

Hi ShihabKhan,

There are handled by user itself.

To remove from chrome add the below line style.

<style type="text/css">
    @page
    {
        margin: 0;
    }
</style>

To remove from mozilla add tmoznomarginboxes mozdisallowselectionprint in the head tag.

<script type="text/javascript">
    function PrintPanel() {
        var panel = document.getElementById("<%=pnlContents.ClientID %>");
        var printWindow = window.open('', '', 'height=400,width=800');
        printWindow.document.write('<html moznomarginboxes mozdisallowselectionprint><head><title>DIV Contents</title>');
        printWindow.document.write('</head><body >');
        printWindow.document.write(panel.innerHTML);
        printWindow.document.write('</body></html>');
        // remove title from IE.
        printWindow.document.title = '';
        printWindow.document.close();
        setTimeout(function () {
            printWindow.print();
        }, 500);
        return false;
    }
</script>

For IE you can not control it with javascript. You can remove only the title.