title: Enabel Excel Autofilter when export the data from gridview
body: <p><strong>I really appreciate if anyone can help me on how can I enable the filter feature on Excel when exporting the data from gridview.( Excel Autofilter)</strong></p>
  
  <pre><code> public ActionResult ExportToExcel(List&lt;EventViewModel&gt; list)
      {
          try
          {
             // Main
               GridView gv = new GridView();
              gv.DataSource = list.ToList();
              gv.DataBind();
  
              Response.ClearContent();
              Response.Buffer = true;
              Response.Charset = "";
              Response.AddHeader("content-disposition", "attachment; filename=filename.xls");//Response.AddHeader("content-disposition", "inline; filename=Excel.xls");
              Response.ContentType = "application/excel";
  
              StringWriter sw = new StringWriter();
              HtmlTextWriter htw = new HtmlTextWriter(sw);
              gv.RenderControl(htw);
              Response.Output.Write(sw.ToString());
              Response.Flush();
              Response.End();
  
              return RedirectToAction("Index");
  
          }
          catch (System.Exception e)
          { 
              return View("Error");
          }
      }
  </code></pre>