Follow the below steps
1. Render GridView control to HTMLTextWriter
2. Copy TextWriter content to a StringBuilder variable
3. Prepare a html table row (
<table><tbody><tr></tr></tbody></table>
) with the values for the new row. Each column value should be within separate
<table><tbody><tr><td></td></tr></tbody></table>
4. Using StringBuilder variable, insert the above row to the html just before end table tag (
)
5. Now write the content using Response.Write()
6. This will download an excel with your new row
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Test.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
StringBuilder sb = new StringBuilder(stringWrite.ToString());
sb = sb.Replace("</table>", "<tr><td>Column1</td><td>Column2</td></tr></table>");
Response.Write(sb);
Response.End();