1个回答
展开全部
复制放到html里运行一下
<%@ Page language="c#" Codebehind="WPrint.aspx.cs" AutoEventWireup="false" Inherits="ASPNETPrint._01WindowPrint.WPrint" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function preview()
{
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<center>本部分以上不被打印</center>
<!--startprint-->
<div align="center">
<asp:DataGrid id="dgShow" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</div>
<!--endprint-->
<center>本部分以下不被打印</center>
<div align="center">
<input type="button" name="print" value="预览并打印" onclick="preview()">
</div>
<style> @media Print { .Noprn { DISPLAY: none }}
</style>
<p class="Noprn">不打印</p>
<table id="datagrid">
<tr>
<td>打印</td>
</tr>
</table>
<input class="Noprn" type="button" onclick="window.print()" value="print">
</form>
</body>
</HTML>
<%@ Page language="c#" Codebehind="WPrint.aspx.cs" AutoEventWireup="false" Inherits="ASPNETPrint._01WindowPrint.WPrint" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function preview()
{
bdhtml=window.document.body.innerHTML;
sprnstr="<!--startprint-->";
eprnstr="<!--endprint-->";
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
window.document.body.innerHTML=prnhtml;
window.print();
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="WebForm1" method="post" runat="server">
<center>本部分以上不被打印</center>
<!--startprint-->
<div align="center">
<asp:DataGrid id="dgShow" runat="server" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
</div>
<!--endprint-->
<center>本部分以下不被打印</center>
<div align="center">
<input type="button" name="print" value="预览并打印" onclick="preview()">
</div>
<style> @media Print { .Noprn { DISPLAY: none }}
</style>
<p class="Noprn">不打印</p>
<table id="datagrid">
<tr>
<td>打印</td>
</tr>
</table>
<input class="Noprn" type="button" onclick="window.print()" value="print">
</form>
</body>
</HTML>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |