title: Exporting GridView to Excel exports only <div> and </div>
body: <p>I am new to .net. I have written a code to export a gridview into excel. the export works but instead of getting data of gridview I get  tags in the exported document. Same case if I exported the gridview to docs. This is what exported file looks like</p>
  
  <p><img src="https://i.stack.imgur.com/iYCEQ.png" alt="enter image description here"></p>
  
  <p>The GridView I have gets populated by a search query. Here is an excerpt of my code:</p>
  
  <pre><code>Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
      MsgBox("Exporting")
  
      Response.Clear()
      Response.Buffer = True
  
      Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls")
      Response.Charset = ""
      Response.ContentType = "application/vnd.ms-excel"
  
      Dim sw As New StringWriter()
      Dim hw As New HtmlTextWriter(sw)
  
      gridviewID.AllowPaging = False
      gridviewID.DataSource = gvDataTable
      gridviewID.DataBind()
      gridviewID.RenderControl(hw)
  
      Response.Write(sw.ToString())
      Response.Flush()
      Response.End()
  </code></pre>
  
  <p>My GridView is not inside a Form tag as I already have a Form tag in my master page. This is how my GridView looks:</p>
  
  <pre><code>&lt;asp:GridView ID="gridviewID" runat="server"
                          AutoGenerateColumns="False" onrowcommand="searchResultsGridView_RowCommand"&gt;
                          &lt;Columns&gt;
                              &lt;asp:BoundField DataField="logNum" HeaderText="ID" ReadOnly="True" ItemStyle-CssClass="hideme" /&gt;
  
                              &lt;asp:BoundField DataField="workIDName" HeaderText="work NAME"
                                SortExpression="workIDName" ReadOnly="True" /&gt;
  
                              &lt;asp:BoundField DataField="LeadIdName" HeaderText=" LEAD"
                                SortExpression="LeadIdName" ReadOnly="True" /&gt;
  
                              &lt;asp:BoundField DataField="Lead_Name2"// and a lot of fields till closing tags
  </code></pre>
  
  <p>I have placed <strong>verifyrendering function</strong> right after my page load.
  Placing this function right after export function wouldn't work. It would not let me export at all.</p>
  
  <p>What could i be possibly doing wrong? </p>