Kindly help me how to export to excel on button click event
as when I'm clicking it is not giving any error but it is not exporting the gridview.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.ReadData();
}
}
private void ReadData()
{
DBManager dm = new DBManager();
dm.MyCmdText = ("select sd.Symbol,sd.[Last],sd.[Volume],sd.[High],sd.[Low],sd.[Close],sd.[Open] from tblstockdetails sd,tblstockmaster sm where sm.symbol = sd.symbol and sm.fo='Y' order by sm.Symbol asc");
DataTable dt = dm.ReadBulkRecord();
if (dt.Rows.Count > 0)
{
Grid_Live.DataSource = dt;
Grid_Live.DataBind();
}
else
{
Grid_Live.DataSource = null;
Grid_Live.DataBind();
}
}
protected void Excel_Click(object sender, ImageClickEventArgs e)
{
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=Users.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter(); ;
HtmlTextWriter htm = new HtmlTextWriter(sw);
Grid_Live.AllowPaging = false;
this.ReadData();
Grid_Live.RenderControl(htm);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}