通过GridView导出数据实现打印

public override void VerifyRenderingInServerForm(Control control)
    {
        // Confirms that an HtmlForm control is rendered for
    }

private void OutPutByGridview()
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
        Response.Charset = "UTF-8";
        Response.ContentType = "application/vnd.doc";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        GridView1.AllowPaging = false;
        BindData("");
        GridView1.RenderControl(htmlWrite);

        Response.Write(stringWrite.ToString());
        Response.End();
        GridView1.AllowPaging = true;
        BindData("");
    }

posted @ 2010-06-23 13:13  JasonNET  阅读(329)  评论(0编辑  收藏  举报