用于报告的打印按钮 [英] Print Button for report

查看:80
本文介绍了用于报告的打印按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,当用户点击打印按钮时,我所在的打印代码会打印到打印屏幕,供用户单击他们拥有的打印机,然后单击打印。用户是否可以单击打印按钮并打印出用户填写的表单报告?我正在使用VS 2010和C#。



I have a form that when the user clicks the print button the print code that I have in place prints to the print screen for the user to click the printer that they have then click print. Is there a way that the user can click the print button and it prints out a report of the form that was filled out by the user? I am using VS 2010 with C#.

protected void Page_Load(object sender, EventArgs e)
   {
       ButtonPrint.Attributes.Add("onclick", "window.print(); return false");
   }

推荐答案

检查这个

如何在ASP.NET中打印 [ ^ ]



FYI

在ASP.NET中动态创建打印预览页面 [ ^ ]

在ASP.NET中打印 [ ^ ](这还有一些额外的东西)
Check this
How to Print in ASP.NET[^]

FYI
Creating print preview page dynamically in ASP.NET[^]
Printing in ASP.NET[^](This has some additional things)


protected void btnprint_Click(object sender, EventArgs e)
    {
        Session["ctrl"] = Panel2;
        Control ctrl = (Control)Session["ctrl"];
        PrintWebControl(ctrl);
    }

    public static void PrintWebControl(Control ControlToPrint)
    {
        StringWriter stringWrite = new StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
        if (ControlToPrint is WebControl)
        {
            Unit w = new Unit(100, UnitType.Percentage);
            ((WebControl)ControlToPrint).Width = w;
        }
        Page pg = new Page();
        pg.EnableEventValidation = false;
        HtmlForm frm = new HtmlForm();
        pg.Controls.Add(frm);
        frm.Attributes.Add("runat", "server");
        frm.Controls.Add(ControlToPrint);
        pg.DesignerInitialize();
        pg.RenderControl(htmlWrite);
        string strHTML = stringWrite.ToString();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Write(strHTML);
        HttpContext.Current.Response.Write("<script>window.print();</script>");
        HttpContext.Current.Response.End();
    }


这篇关于用于报告的打印按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆