把数据放到datalist里面,然后把以下代码贴到click事件里就ok了 Response.Clear();
Response.BufferOutput = true;
//设定输出的字符集
Response.Charset = "GB2312";
//假定导出的文件名为FileName.doc
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.doc");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
////设置导出文件的格式
Response.ContentType = "application/ms-word";
//关闭ViewState
DataList1.EnableViewState = false;
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
DataList1.RenderControl(textWriter);
// //把HTML写回浏览器
Response.Write(stringWriter.ToString());
Response.End();