It is easy to make excel file of gridview just copy and paste the following code to your csharp code and change the gridview name. It will generate the excel sheet easily. please don't forget to give comments
protected void Button1_Click(object sender, EventArgs e)
{
HtmlForm form = new HtmlForm();
string attachment = "attachment; filename=Employee.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
form.Controls.Add(gvContact);
this.Controls.Add(form);
form.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();
}
Showing posts with label Export. Show all posts
Showing posts with label Export. Show all posts
Subscribe to:
Posts (Atom)