操作列含打印功能
<asp:TemplateField HeaderText="操作">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Wrap="False" HorizontalAlign="Center" />
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" ToolTip="编辑" _KeyID='<%#Eval("BizFormID") %>'
ImageUrl="~/images/com/dg_edit.gif" CausesValidation="False" OnClientClick=" return openEditor(this, 'Edit');">
</asp:ImageButton>
<a _visible="FILECP_LIST$PRINT" onclick="return Print(this);" title="打印" target="_blank"
id="Da" _receivedate='<%#Eval("ReceiveDate")%>' _handlenum='<%#Eval("HandleNum")%>'
_communicationsunit='<%#Eval("CommunicationsUnit")%>' _receiptnum='<%#Eval("ReceiptNum")%>'
_urgency='<%#Eval("Urgency")%>' _title='<%#Eval("Title")%>' _draftopinion='<%#Eval("DraftOpinion")%>'
_leaderopinion='<%#Eval("LeaderOpinion")%>' _results='<%#Eval("Results")%>' _contactuser='<%#Eval("ContactUser")%>'
_contacttel='<%#Eval("ContactTel")%>'>
<img id="Img1" alt="" runat="server" src="~/Images/icon_print.gif" style="border: 0px;" /></a>
<asp:ImageButton ID="ImageButton3" runat="server" ToolTip="删除" ImageUrl="~/images/com/dg_del.gif"
_KeyID='<%#Eval("BizFormID") %>' CausesValidation="False" OnClientClick=" return confirm('您确认要删除吗?') "
OnClick="DeleteApplication"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
在打印的的操作列中绑定需要打印的该条数据。
js脚本代码:
var WebBrowser;
// 验证浏览器是否支持 AcitveX
function ValidBrowser() {
if (null == WebBrowser) {
try {
WebBrowser = new ActiveXObject("InternetExplorer.Application");
}
catch (ex) {
alert("浏览器不允许AcitveX,请联系管理员设置!");
return;
}
WebBrowser.FullScreen = true;
WebBrowser.Navigate2(window.location.protocol + "//" + window.location.host + "/Modules/Workflow/FileCP/CPPrint.html");
}
else {
if (WebBrowser.Busy) {
alert("已经有打印任务在等待确认,请先完成该确认操作!");
//WaitingPrint();
return;
}
// WebBrowser.Refresh(); //这里是要注释掉,不注释掉的话就会导致打印内容累加。
}
};
function getPrintData() {
WebBrowser.Document.body.innerHTML = '<div border="0" align="center" class="print">' +
'<DIV class="print" align=center border="0">' +
'<DIV style="MARGIN-TOP: 10px; WIDTH: 100%; HEIGHT: 700px">' +
'<DIV id=Content_container>' +
'<DIV class="qj_hed">' +
'<H1 style="MARGIN-TOP: -50px; WIDTH: 70%; FLOAT: left" class="qj_title">33333</H1>' +
'<DIV style="TOP: 0px" class="urgency">紧急程度</DIV>' +
'<DIV style="BORDER-TOP: medium none; TOP: 20px" class="urgency">' + _urgency + '</DIV>' +
'<DIV style="TEXT-ALIGN: left; CLEAR: both" class="qj_da"><SPAN class="qj_sp">收文日期:' + _receivedate + '</SPAN><SPAN>办文编号:' + _handlenum + '</SPAN><SPAN style="MARGIN-TOP: -70px; FLOAT: right"></SPAN></DIV></DIV>' +
'<TABLE style="BORDER-BOTTOM: #000 1px solid; BORDER-RIGHT: #000 1px solid" class="db_tab" border=0 cellSpacing=0 cellPadding=0 width="100%">' +
'<TBODY><TR>' +
'<TD class="db_tab_l" width="10%" align=center>来文<BR>单位</TD>' +
'<TD class="db_tab_r">' + _communicationsunit + '</TD>' +
'<TD width="10%">收文<BR>编号</TD>' +
'<TD>' + _receiptnum + '</TD></TR>' +
'<TR>' +
'<TD style="TEXT-ALIGN: center" class="db_tab_l">来文<BR>标题</TD>' +
'<TD colSpan=3>' + _title + '</TD></TR>' +
'<TR>' +
'<TD style="TEXT-ALIGN: center">拟<BR>办<BR>意<BR>见</TD>' +
'<TD colSpan=3>' + _draftopinion + '</TD></TR>' +
'<TR>' +
'<TD style="TEXT-ALIGN: center">领<BR>导<BR>批<BR>示</TD>' +
'<TD colSpan=3>' + _leaderopinion + '</TD></TR>' +
'<TR>' +
'<TD style="TEXT-ALIGN: center">处<BR>理<BR>结<BR>果</TD>' +
'<TD colSpan=3>' + _results + '</TD></TR></TBODY></TABLE>' +
'<DIV style="TEXT-ALIGN: left" class="qj_da"><SPAN class="qj_sp">联系人:' + _contactuser + '</SPAN><SPAN>联系人电话:' + _contacttel + '</SPAN></DIV></DIV></DIV></DIV>';
WebBrowser.ExecWB(7, 1);
window.blur(); //这里是要让当前window失去焦点,从而使WebBrowser打开在前。
}
var _title, _receivedate, _handlenum, _communicationsunit, _receiptnum, _urgency, _draftopinion, _contactuser, _leaderopinion, _results, _contacttel;
function Print(_this) {
_title = $(_this).attr('_title');
_receivedate = $(_this).attr('_receivedate');
_handlenum = $(_this).attr('_handlenum');
_communicationsunit = $(_this).attr('_communicationsunit');
_receiptnum = $(_this).attr('_receiptnum');
_urgency = $(_this).attr('_urgency');
_draftopinion = $(_this).attr('_draftopinion');
_contactuser = $(_this).attr('_contactuser');
_leaderopinion = $(_this).attr('_leaderopinion');
_results = $(_this).attr('_results');
_contacttel = $(_this).attr('_contacttel');
ValidBrowser(); //验证浏览器是否支持 AcitveX
if ("undefined" != typeof (WebBrowser) && WebBrowser.ReadyState == 4 && !WebBrowser.Busy) {
setTimeout("getPrintData()", 1500);
}
}
Print.html需要打印的数据承载页面
//注意:关于放入承载页面的html的样式,要以外部样式文件的方式,引入到承载页面里。
<html>
<head>
<link media="print" href="Css/Print.css" type="text/css" rel="stylesheet" />
<link href="../../App_Themes/blue2/module/docform/docform.css" rel="stylesheet" type="text/css" />
</head>
<body>
</body>
</html>
方法2
也可以用ajax请求ashx获取想要打印的数据。

浙公网安备 33010602011771号