export gridview to excel error
dear all, i tried the code below to make the export to excel, but not working correctly i used this thread lin开发者_JAVA技巧k 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();
did you try add to the aspx page directive
EnableEventValidation ="false"
精彩评论