打印指定内容:
代码就是这样的.
<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里的内容放到另一个Web页面中然后执行打印!
第二种方法是,先将页面上的除了你要打印的标签外隐藏,接着执行打印,在打印后将页面上的标签全部显示
代码如下:
function printer()
{
beforeprint();
window.focus();
window.print()
afterprint();
}
function beforeprint()
{
for(i = 0; i < document.all.length; i++)
{
if ((document.all(i).id.indexOf("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()就可以了
分享到:
相关推荐
使用C#打印DataGridView控件中的数据,实现分页打印,每页打印10条记录
asp.net中实现打印gridview代码不错的!!!
C#编写,可以更方便的打印Gridview里显示的信息。可以动态的选择要打印的字段,样式等信息。 特别注明:使用Vs2008编写,.net framework用的是2.0版的
C#打印很好的打印程序
GRIDVIEW动态添加列及RDLC打印GRIDVIEW动态添加列及RDLC打印GRIDVIEW动态添加列及RDLC打印
代码如下: var hkey_root = “HKEY_CURRENT_USER”; var hkey_path = “\\Software\\Microsoft\\Internet Explorer\\PageSetup\\”; var hkey_key; function printPage() { try { var RegWsh = new ActiveXObject(...
C#打印预览和打印datagridview
打印gridview
gridview 打印 js打印 很简单,很实用,呵呵
GridView打印代码
c#winform datagridview打印整个列表的例子,源码奉上
print类,提供打印gridview功能,可以写打印标题等等
一个基于C#+ASP.NET实现的GridView翻页浏览控件打印输出程序例子。
BS下asp.net实现gridview浏览器打印和导出excel.手敲代码可用
动态生成GridView,非常实用,特别是用于打印GridView信息用作的双GridView,导出
C#与打印机之间的调用,打印机可打印GRIDVIEW内的内容,~~~~~~~
对于页面的打印这也是一个非常有用的技术,因为用户可以灵活地选择GridView的列打印。 背景: RowCreated 和ItemDataBound 事件允许你用多种方式注入HTML, CSS,和JavaScript 来增强GridView 控件的功能。 示例...
GridView打印,和分页的问题,希望给你点启发!
asp.net GridView窍门程序GridView窍门程序GridView窍门程序GridView窍门程序