"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Monday, October 22, 2012

Print a div or grid in javascript

 Hi *.*,
 

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Print Gridview Data in asp.net</title>
<script type="text/javascript">
function PrintGridData() {
var prtGrid = document.getElementById('<%=gvUserInfo.ClientID %>');
prtGrid.border = 0;
var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
prtwin.document.write(prtGrid.outerHTML);
prtwin.document.close();
prtwin.focus();
prtwin.print();
prtwin.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<b>Print Gridview Data</b><br /><br />
<asp:GridView ID="gvUserInfo" runat="server" >
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White"/>
</asp:GridView>
<input type="button" id="btnPrint" value="Print" onclick="PrintGridData()" />
</div>
</form>
</body>
</html>




If u had any trouble just ask, Happy to help u :)
Stay Tune...
Have a nice day... 'N happy Coding :)

No comments: