导出gridview以出现错误

时间:2010-12-09 20:29:43

标签: vb.net

亲爱的,我尝试使用下面的代码将导出导出为ex​​cel,但无法正常工作 我用过这个帖子 link text

HtmlForm form = new HtmlForm(); 
string attachment = "attachment; filename=Patients.xls"; 
Response.ClearContent(); 
Response.AddHeader("content-disposition", attachment); 
Response.ContentType = "application/ms-excel"; 
StringWriter stw = new StringWriter(); 
HtmlTextWriter htextw = new HtmlTextWriter(stw); 
form.Controls.Add(gridview1); 
this.Controls.Add(form); 
form.RenderControl(htextw); 
Response.Write(stw.ToString()); 
Response.End(); 

1 个答案:

答案 0 :(得分:1)

您是否尝试添加到aspx页面指令

EnableEventValidation ="false"