if (GridView1.Rows.Count > 0)
{
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
Response.Write("Add anything (tag or text) as per requirement");
GridView1.HeaderStyle.Font.Bold = true;
GridView1.HeaderStyle.BackColor = System.Drawing.Color.Black;
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
HtmlForm frm = new HtmlForm();
this.Controls.Add(frm);
frm.Controls.Add(GridView1);
frm.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
A Literal Web Server control doesn't have any visual appearance on a Web Form but is used to insert literal text into a Web Form. This control makes it possible to add HTML code directly in the code designer window without switching to design view and clicking the HTML button to edit the HTML.
The notable property of this control is the text property which is the text that is inserted into the Web Form.
Example
The following line of code demonstrates that.
Literal1.Text = "Literal Demo"