请问DATAGRID下载到客户端的问题!
目标:将DATAGRID中的数据保存到客户端,保存为.TXT文件,代码如下,但实现的效果是.TXT文件中包含了"<TABLE><TR>...",请问如何下载为如下格式
header1 header2 header3
A1 B1 C1
A2 B2 C2
A3 B3 C3
代码:
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+ls_filename);
HttpContext.Current.Response.Charset ="GB2312";
HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType ="application/text";
ctl.Page.EnableViewState =false;
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
其中的CTL为DATASET的对象