protected void BindData()
{
sqlcommand cmd=new sqlCommand("Select * from Emp");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
gvdetails1.DataSource = ds.Tables[0];
gvdetails1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string attachment = "attachment; filename=export.xls;hdr=yes";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htm = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
gvdetails1.Parent.Controls.Add(frm);
frm.Attributes["Runat"] = "Server";
frm.Controls.Add(gvdetails1);
frm.RenderControl(htm);
Response.Write(sw.ToString());
Response.End();
}