gridview 인쇄

2494 단어 JavaScripthtmlWebasp
지정 한 내용 인쇄:
 
코드 가 이 렇 습 니 다.
<html>
<head>
<script type="text/javascript" language="javascript">
function printPage() {
var newWin = window.open('printer.html','','');
var titleHTML = document.getElementById("printdiv").innerHTML;
newWin.document.write(titleHTML);
newWin.document.location.reload();
newWin.print();

newWin.close();
}
</script>
</head>
<body>
<div id="printdiv">
<table class="sontable" cellspacing="0" cellpadding="0" style="width: 13%">
<tr>
<td style="width: 700px; height: 161px">
<asp:GridView ID="GridData" runat="server" CellPadding="3" CellSpacing="0" BorderWidth="1px" BackColor="LightSteelBlue" BorderColor="White" BorderStyle="None" Font-Size="12px" Width="543px" Height="20px" OnRowDataBound="GridData_RowDataBound">
<RowStyle BackColor="GhostWhite" BorderColor="#006699" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" Wrap="True" />
<HeaderStyle Height="25px" BackColor="#006699" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" CssClass="Freezing"/>
</asp:GridView>  
</td>
</tr>
</table>
</div>
<a href="javascript:;" onclick="printPage()">  </a>
</body>
</html>
 
 이 원 리 는 GridView 의 내용 을 다른 웹 페이지 에 넣 고 인쇄 하 는 것 입 니 다!두 번 째 방법 은 인쇄 할 탭 을 제외 하고 페이지 에 있 는 탭 을 숨 기 고 인쇄 를 실행 하 는 것 입 니 다. 인쇄 후 페이지 에 있 는 탭 을 모두 표시 하 는 코드 는 다음 과 같 습 니 다: function printer () { beforeprint(); window.focus(); window.print() afterprint();}function beforeprint(){ for(i = 0; i < document.all.length; i++) {   if ((document. all (i). id. index Of ("div table")! = - 1) & & & document. all (i). tagName = = "TABLE") / / 그 중 "div table" 인쇄 할 태그 ID 를 검사 합 니 다  {  document.all(i).style.display="none";  } }}function afterprint(){ for(i = 0; i < document.all.length; i++) {  if ((document.all(i).id.indexOf("div_table_")!=-1) && document.all(i).tagName=="TABLE")  {  document.all(i).style.display="block";  } }}printer () 를 호출 하면 됩 니 다.

좋은 웹페이지 즐겨찾기