export gridview with columns hide
Make enableEventValidation="false"
protected void Imageexcel_Click(object sender, ImageClickEventArgs e)
{
GridView1.Columns[0].Visible = false;
GridView1.Columns[8].Visible = false;
string attachment = "attachment; filename=patientlist.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
// HttpContext.Current.Response.Write("<img src='http://ghrce.edu.in/pic/adminlogin.JPG'>");
//HttpContext.Current.Response.Write("<br><br><br><br><br><br><br>");
HttpContext.Current.Response.Write("<br>");
// Create a form to contain the grid
HtmlForm frm = new HtmlForm();
GridView1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(GridView1);
frm.RenderControl(htw);
//GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
protected void Imageexcel_Click(object sender, ImageClickEventArgs e)
{
GridView1.Columns[0].Visible = false;
GridView1.Columns[8].Visible = false;
string attachment = "attachment; filename=patientlist.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
// HttpContext.Current.Response.Write("<img src='http://ghrce.edu.in/pic/adminlogin.JPG'>");
//HttpContext.Current.Response.Write("<br><br><br><br><br><br><br>");
HttpContext.Current.Response.Write("<br>");
// Create a form to contain the grid
HtmlForm frm = new HtmlForm();
GridView1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(GridView1);
frm.RenderControl(htw);
//GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}