日期:2014-05-18  浏览次数:20429 次

高分求:网页中如何只打印gridview内容
高分求:网页中如何只打印gridview内容

------解决方案--------------------
protected override void Render(HtmlTextWriter writer)
{
Response.ContentType = "application/ms-word ";
Response.AddHeader( "Content-Disposition ", "attatchment;filename=test.doc ");
GridViewID.RenderControl(writer);
}
------解决方案--------------------
1.打印的时候跳到新的一页,只有一个GridView的,不要分页把全部数据显示出来,然后用IE打印
2.可以把资料写到Excle中再打印
3.只打印需要的内容
js:
----------------------------------------
<script language= "javascript ">
<!--
function PrintNote()
{
var PrintWin=window.open( 'about:blank ', 'Print ');
PrintWin.document.write( ' <object id= "WebBrowser " width=0 height=0 classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 "> </object> ' + document.all( "PrintContent ").innerHTML);
PrintWin.document.all.WebBrowser.ExecWB(7,1);
PrintWin.close();
}
-->
</script>
--------------------------------------------
内容用 <div> 装起来,并把DIV设置ID
<div id= "PrintContent " align= "center ">
your GridView
</div>
------------------------------------
<input onclick= "javascript:PrintNote(); " type= "button " value= "打印 ">
------解决方案--------------------
从另外一个角度考虑,也可以用样式来实现不需要打印的区域以及分页打印:
样式定义:
<style media= "print ">
.Noprint { DISPLAY: none }
.PageNext { PAGE-BREAK-AFTER: always }
</style>

样式使用(不需要打印的区域):
<div class= "Noprint ">
不需要打印的部分
</div>

样式使用(下一页):
<div class= "PageNext ">
下一页的部分
</div>