title: GridView - Removing Edit and Delete columns while exporting to Excel
body: <p>Thank you for viewing my question and helping. I have a asp.net application built in C#. The application has a simple gridview. I have a button to export the gridview into excel, which works as well. However, my gridview has a edit link in column 1 and a delete button in column 2. Both if these columns export to excel as well. How do I stop these two columns from exporting? I have tried a few things:</p>
  
  <pre><code>GridView1.Columns.RemoveAt(0);
  GridView1.Columns.RemoveAt(1);
  </code></pre>
  
  <p>and...</p>
  
  <pre><code>GridView1.Column(0).visible = false;
  </code></pre>
  
  <p>I did a data bind after each of these while trying, but it simply does not work. I'll post my code below, and maybe someone can help me out! Thanks!</p>
  
  <pre><code> public void ExportGridToExcel(GridView grdGridView, string fileName)
              {
  
  
              Response.Clear();
              Response.AddHeader("content-disposition",
              string.Format("attachment;filename={0}.xls", fileName));
              Response.Charset = "";
              Response.ContentType = "application/vnd.xls";
  
              StringWriter stringWrite = new StringWriter();
              HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
              grdGridView.RenderControl(htmlWrite);
              GridView1.Columns.RemoveAt(0);
              Response.Write(stringWrite.ToString());
              Response.End();
  
              GridView1.AllowPaging = false;
  
      }
  </code></pre>
  
  <p>The girdview has the edit feature set to true, and the delete button is a template field as below:</p>
  
  <pre><code>&lt;Columns&gt;
              &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
              &lt;asp:Button ID="btnDelete" CommandName="Delete" runat="server"     Text="Delete" CssClass="okbutton" OnClientClick="return confirm('Are you sure you want to delete this entry?');" /&gt;
              &lt;/ItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
  </code></pre>