谁有C#+ACCESS的打印DATAGRIDVIEW控件中数据的代码吗?
分享下 不胜感谢

解决方案 »

  1.   

    function PreviewPrint()
    {
         bdhtml=window.document.body.innerHTML;
         sprnstr="<!--startprint-->";
         eprnstr="<!--endprint-->";
         prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
         prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
         window.document.body.innerHTML=prnhtml;
         var obj=document.getElementById("GridView1");
         if (obj!=null)
         {
             var rows = obj.rows;
             var hide=rows.length-1;
             obj.rows(hide).style.display = "none";
         }
         window.print();
         
          window.parent.returnValue='0';
    }
    function NoPagePrint()
    {
         bdhtml=window.document.body.innerHTML;
         sprnstr="<!--startprint-->";
         eprnstr="<!--endprint-->";
         prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
         prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
         window.document.body.innerHTML=prnhtml;
         window.print();    
         window.parent.returnValue='0';
         window.parent.close();
    }
    function PreviewPrintCancel() 
    {
        window.parent.returnValue='0';
        window.parent.close();
    }
     function CloseWin()
    {
    window.parent.returnValue='1';
    window.parent.close();
    }
    function DoNothingAndCloseWin()
    {
    window.parent.returnValue='DoNothing';
    }把这个加在DATAGRIDVIEW外<!--startprint-->   <!--endprint-->  
    protected void Button1_Click(object sender, ImageClickEventArgs e)
            {
                Response.ContentType = "application/ms-word";
                Response.AddHeader("Content-Disposition", "inline;filename=DocumentPrint.doc");
                StringBuilder sb = new StringBuilder();
                System.IO.StringWriter sw = new System.IO.StringWriter(sb);
                System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
                sb.Append("<html><body>");
                this.PrintA.RenderControl(hw);
                sb.Append("</body></html>");
                Response.Write(sb.ToString());
                Response.End();
            }