用一个B/S写一个点击一个按钮然后出现一个表格的框架然后填写内容打印出来!
有相关的项目和源代码参考的!
点击一个按钮可以出现一个类似于下图的表格,并且能填写信息跟打印!
用UpdatePanel结合PageRequestManager,先向服务端发出请求,请求完毕后再调用客服端打印代码。
代码:
C#:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; public partial class PrintTest : System.Web.UI.Page { protected void btnPrint_Click(object sender, EventArgs e) { PlaceHolder1.Controls.Add(new LiteralControl("<div>这里就是你要打印的内容</div>")); } }
HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPrint.aspx.cs" Inherits="TestPrint" %> <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <style type="text/css"> @media print { .noneprint { display : none; } } </style> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <script type="text/javascript"> var postbackElement; Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest); Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest); function beginRequest(sender, args) { postbackElement = args.get_postBackElement(); } function endRequest(sender, args) { if (typeof(postbackElement) === "undefined") { return; } else if (postbackElement.id.toLowerCase().indexOf('btnprint') > -1) { window.print(); } } </script> <%-- noneprint Begin--%> <div class="noneprint"> <asp:Button ID="btnPrint" runat="server" Text="Print" onclick="btnPrint_Click" /> </div> <%-- noneprint End--%> <%-- print Begin--%> <div> <asp:UpdatePanel id="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:PlaceHolder ID="PlaceHolder1" runat="server" EnableViewState="false"></asp:PlaceHolder> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnPrint" /> </Triggers> </asp:UpdatePanel> </div> <%-- print End--%> </form> </body> </html>
<html> <head> <script> window.onload = function() { window.print(); } </script> </head> <body> <table> <tr> <td>name</td> </tr> <tr> <td>name</td> </tr> </table> </body> </html>
function tableprint()
{
//写弹出表格的js代码
window.print();
}
可以使用rdlc报表。这样的打印出来效果应该还是很不错的。