//此方法不可少
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
protected void btnExpExcel_Click(object sender, EventArgs e)
{
this.Response.Clear();
this.Response.AppendHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMddhhmmss") + "FileName.xls");
this.Response.Charset = "UTF8"; //输出的字符集
this.Response.ContentEncoding = System.Text.Encoding.UTF8; //编码类型
Response.ContentType = "application/vnd.ms-excel"; //输出Excel
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.gvData.RenderControl(hw);
this.Response.Write(tw.ToString());
this.Response.End();
}