GridView数据导出

//调用Method
 Export("application/ms-excel", "Employee information.xls");
 Export("application/ms-word", "员工信息.doc");
 
//定义method
private void Export(string FileType, string FileName)
    {
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        GridView1.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }
posted @ 2009-08-06 15:44  只想做好  阅读(251)  评论(0编辑  收藏  举报