Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8098197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:00:24+00:00 2026-06-05T22:00:24+00:00

I have a gridview that needs to be exported to Excel. I have managed

  • 0

I have a gridview that needs to be exported to Excel. I have managed to remove the Checkboxes from Rows but don’t know how to remove from the Header and also delete the Checkbox Column entirely. Thanks for help.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Id">
    <Columns>
        <asp:TemplateField HeaderText="Select" >
            <HeaderTemplate>
                <input id="chkAll" onclick="checkAll(this);" runat="server" type="checkbox" />
            </HeaderTemplate>
            <ItemTemplate>
            <asp:CheckBox  ID="CheckBox1" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Event" HeaderText="Event" SortExpression="Event" />
        <asp:BoundField DataField="Event_Description" HeaderText="Event_Description" SortExpression="Event_Description" />
        <asp:BoundField DataField="Start_Date" HeaderText="Start_Date" SortExpression="Start_Date" />
    </Columns>
    </asp:GridView>

Here’s the backend C# code to export to excel.

protected void download_Click(object sender, EventArgs e)
{
    PrepareGridViewForExport(GridView1);
    Response.ClearContent(); 
    Response.AddHeader("content-disposition", "attachment; filename=GridViewToExcel.xls"); 
    Response.ContentType = "application/excel"; 
    StringWriter sWriter = new StringWriter();
    HtmlTextWriter hTextWriter = new HtmlTextWriter(sWriter);
    GridView1.RenderControl(hTextWriter);
    Response.Write(sWriter.ToString());
    Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
private void PrepareGridViewForExport(Control gv)
{
    Literal l = new Literal();
    string name = String.Empty;
    for (int i = 0; i < gv.Controls.Count; i++)
    {
        if (gv.Controls[i].GetType() == typeof(CheckBox))
        {
            gv.Controls.Remove(gv.Controls[i]);
            gv.Controls.AddAt(i, l);
        }
        if (gv.Controls[i].HasControls())
        {
            PrepareGridViewForExport(gv.Controls[i]);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:00:27+00:00Added an answer on June 5, 2026 at 10:00 pm

    Try out this export function , which hides not needed column i.e column 0 of the row…

    protected void btnExportExcel_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.DataBind(); 
    
    
        GridView1.HeaderRow.Cells[0].Visible = false; 
    
        for (int i = 0; i < GridView1.Rows.Count;i++ )
        {
           GridViewRow row = GridView1.Rows[i];
           row.Cells[0].Visible = false;
           row.Cells[0].FindControl("chkCol0").Visible = false; 
         }
        GridView1.RenderControl(hw);
        Response.Write(style);
        Response.Output.Write(sw.ToString());
        Response.End();
    }
    

    or

    On your export, drop the column. Something something like:

    GridView1.Columns[0].visible = false;
     GridView1.DataBind();
      GridView1.RenderControl(htmlWrite);
     Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView that needs to display either x amount of columns from
Need some help with DataFormatString in GridView. I have a Double value that needs
I have a UserControl, which is basically a wrapper for a GridView that needs
I have a gridview with about 300-400 rows that I use for reporting; it
I have a an excel file that has been manually populated, and now needs
I have a GridView bound to an ICollection<UserAnswer> that needs to show two columns:
I have a custom GridView that will show 6 rows of data as a
I have radio button list in a gridview that needs to be bound to
I have a gridview that is populated from an entitydatasource in asp.net. In my
I have a GridView that I need to dynamically add TemplateField elements to. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.