首页 新闻 会员 周边

用一个B/S写一个点击一个按钮然后出现一个表格的框架然后打印出来!

0
悬赏园豆:80 [已解决问题] 解决于 2012-09-11 10:39

用一个B/S写一个点击一个按钮然后出现一个表格的框架然后填写内容打印出来!

有相关的项目和源代码参考的!

问题补充:

点击一个按钮可以出现一个类似于下图的表格,并且能填写信息跟打印!

水嫩小白菜的主页 水嫩小白菜 | 初学一级 | 园豆:3
提问于:2012-08-19 20:29
< >
分享
最佳答案
0

用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>
收获园豆:80
眯妖 | 小虾三级 |园豆:820 | 2012-08-30 20:11
其他回答(3)
0
<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>
chenping2008 | 园豆:9836 (大侠五级) | 2012-08-19 22:32
0

function tableprint()
            {
                //写弹出表格的js代码

               window.print();
            }

jason2013 | 园豆:1998 (小虾三级) | 2012-08-20 08:31
0

可以使用rdlc报表。这样的打印出来效果应该还是很不错的。

※森林小居※ | 园豆:213 (菜鸟二级) | 2012-08-21 12:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册