Response.Clear();
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write("<meta http-equiv=Content-Type content=\"text/html;charset=GB2312\">"); GridView1.EnableViewState = false; System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw); pds.AllowPaging = false;
bind(); GridView1.RenderControl(htw);
Response.Write(style);
Response.Write(sw.ToString());
Response.Flush();
Response.End(); pds.AllowPaging = true;
bind();
代码如上,请说说原理
gridview其实也是一个table,将GRIDVIEW其实等同于遍历TABLR,将其内容输出
bind(); GridView1.RenderControl(htw);
Response.Write(style);
Response.Write(sw.ToString());
Response.Flush();
Response.End(); pds.AllowPaging = true;
bind();
你要关注的是这些