DataGrid中的數據輸出到Excel

根據網上資料整理:
代碼就不需要解釋了。如果DataGridy有某列為按鈕列之類的可以在輸出之前設置列的顯示狀態為不可見,在Response.End()之后再把不能輸出的列的顯示狀態還原。
如:DataGrid.Columns[i].Visible = false;

1             Response.ContentType = "application/vnd.ms-excel";
2             Response.Charset = "GB2312";
3             System.IO.StringWriter sw = new System.IO.StringWriter();
4             System.Web.UI.HtmlTextWriter write = new HtmlTextWriter(sw);
5             TargetGrid.RenderControl(write);
6             Response.Write(sw.ToString());
7             Response.End();

posted on 2008-04-14 16:59  费哥  阅读(517)  评论(1编辑  收藏  举报

导航