表格中的内容即对数据库的检索,要实现的打印功能就是把检索数据库得到的内容打印出来就行

解决方案 »

  1.   

    你将表格里的数据生成excel,然后在用excel自带的打印功能打印就好了
     生成Excel文件如下
        public static void GridViewToExcel(GridView gv, string excelName)
        {
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + excelName + ".xls");        //关闭 ViewState
            //this.EnableViewState = false;
            System.IO.StringWriter tw = new System.IO.StringWriter();        System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
            //获取control的HTML
            gv.RenderControl(hw);
            //把HTML写回浏览器
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
            tw.Close();
            hw.Close();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            //方法重写
        }