日期:2014-05-17 浏览次数:20575 次
DataTable dt = bll.GetPeopleData(); DataGrid dgExport = new DataGrid(); dgExport.DataSource = dt; dgExport.DataBind(); dgExport.AllowPaging = false; //想给表头设置背景色,怎么设置 ,下面这句代码不好用,将整个行都变了 dgExport.HeaderStyle.BackColor = Color.Red; string FileType = "application/ms-excel"; string FileName = "record.xls"; Response.Charset = "big5"; 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); dgExport.RenderControl(hw); Response.Write(tw.ToString()); Response.End();