Monday, March 5, 2012

Print Div in Asp.net code using Java Script

<script language="javascript" type="text/javascript">
        function PrintGridView() {
            printWindow = window.open("", "mywindow", "location=0,status=0,scrollbars=1,resizable=1");

            var strContent = "<html><head>";
            strContent = strContent + "<title" + ">Print Preview</title>";
            strContent = strContent + "<link href=\"App_Themes/Default/Default.css\" type=\"text/css\" rel=\"stylesheet\" />";
            strContent = strContent + "</head><body>";
            strContent = strContent + "<div style='width:100%;text-align:right;'>";
            strContent = strContent + "<input type='button' id='btnPrint' value='Print' style='background:url(../images/button-bg.gif) repeat-x top center;width:62px;height:25px;border:1px solid #666;color:#fff;font-size:12px;font-weight:600;padding-bottom:5px;' onclick='window.print()' />";
            strContent = strContent + "<input type='button' id='btnCancel' value='Cancel' style='background:url(../images/button-bg.gif) repeat-x top center;width:62px;height:25px;border:1px solid #666;color:#fff;font-size:12px;font-weight:600;padding-bottom:5px;' onclick='window.close()' />";
            strContent = strContent + "</div>";

            // Writing GridView Contents
            strContent = strContent + "<div style='width:100%;'>";
            strContent = strContent + document.getElementById('PrintDealerReport').innerHTML;
            //strContent = strContent + document.getElementById('PrintMonthlyDealerSales').innerHTML;
            strContent = strContent + "</div>";

            strContent = strContent + "</body>";
            printWindow.document.write(strContent);
            printWindow.document.close();
            printWindow.focus();
        }
        </script>

No comments:

Post a Comment