private void Export(string FileType, string FileName)
{
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);
Gridview1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
//重写VerifyRenderingInServerForm
public override void VerifyRenderingInServerForm(Control control)
{
}
按钮点击事件里
Export("application/ms-word", "支出信息报表.doc");
.aspx中
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="XGoods.aspx.cs" Inherits="XGoods" %>