当前位置: 代码迷 >> ASP.NET >> 怎么将datagrid的内容导出导excel中
  详细解决方案

怎么将datagrid的内容导出导excel中

热度:9515   发布时间:2013-02-25 00:00:00.0
如何将datagrid的内容导出导excel中
如何将datagrid的内容导出导excel中,我的datagrid是分页的,导出时全部内容导出,而不是当前页的内容

------解决方案--------------------------------------------------------
C# code
       private void Export(string FileType, string FileName)        {            Response.Charset = "GB2312";            Response.ContentEncoding = System.Text.Encoding.UTF7;            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);            datagrid1.RenderControl(hw);            Response.Write(tw.ToString());            Response.End();        }        public override void VerifyRenderingInServerForm(Control control)        {        }        protected void Button1_Click(object sender, EventArgs e)        {            Export("application/ms-excel", "结果.xls");        }
  相关解决方案