- ystem.Web.UI.WebControls.DataGrid dgExport = null;
- System.Web.HttpContext curContext = System.Web.HttpContext.Current;
- System.IO.StringWriter strWriter = null;
- System.Web.UI.HtmlTextWriter htmlWriter = null;
- if (dtData != null)
- {
- curContext.Response.ContentType = "application/vnd.ms-excel";
- curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
- curContext.Response.Charset = "";
- strWriter = new System.IO.StringWriter();
- htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
- dgExport = new System.Web.UI.WebControls.DataGrid();
- dgExport.DataSource = dtData.DefaultView;
- dgExport.AllowPaging = false;
- dgExport.DataBind();
- dgExport.RenderControl(htmlWriter);
- curContext.Response.Write(strWriter.ToString());
- curContext.Response.End();
- }
复制代码 |