I getting an error that one when click on the Export Button in the show shows the data of GridView Along with PageIndexing NUmbers also

protected void btnexcel_Click(object sender, EventArgs e)
    {       
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=Emp.xls");
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }

Recommended Answers

All 2 Replies

Can you please let us know what the error is coming up when you are exporting data to excel file ?

I getting an error that one when click on the Export Button in the show shows the data of GridView Along with PageIndexing NUmbers also

protected void btnexcel_Click(object sender, EventArgs e)
    {       
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=Emp.xls");
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }

In the ExcelSheet i am Getting Pagenumbers along with the Data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.