Here I am trying to export to excel but my problem is that it is not exporting content i added from row data bound.
How do i bind content from rowdatabound while exporting?
protected void BtnExport_Click(object sender, EventArgs e)
{
DataTable dt = blu.GetAllOrg();
lblOrgName.Text = dt.Rows[0]["Org_Name"].ToString();
lblOrgFullAddress.Text = dt.Rows[0]["Full_Address"].ToString();
string emp_id = txtEmpId.Text;
string emp_fullname = "CKs";
Response.ClearContent();
Response.AppendHeader("content-disposition", "attachment; filename=Reports_QuickAttendance of " + '_' + emp_fullname + '(' + emp_id + ')' + ".xls");
Response.ContentType = "application/excel";
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
string style = @"<style> TD { mso-number-format:\@; } </style> ";
Response.Write(style);
HtmlTextWriter htw = new HtmlTextWriter(stringWriter);
htw.Write("<div style='PADDING-RIGHT: 5px; PADDING-LEFT: 5px; text-align:center; PADDING-BOTTOM: 0px; PADDING-TOP: 0px'>");
Panel1.RenderControl(htw);
Panel2.RenderControl(htw);
Panel3.RenderControl(htw);
HtmlTextWriter htw1 = new HtmlTextWriter(stringWriter);
htw1.Write("<div style='PADDING-RIGHT: 5px; PADDING-LEFT: 5px; text-align:left; PADDING-BOTTOM: 0px; PADDING-TOP: 0px'>");
GridView1.RenderControl(htw);
Panel5.RenderControl(htw1);
Response.Write(stringWriter.ToString());
Response.End();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
strPreviousRowID = DataBinder.Eval(e.Row.DataItem, "EMP_ID").ToString();
}
this is datatable that is binding to gridview and which is needed to be exported
DataSet ds = blu.generateReport();
DataTable dt = ds.Tables[0];
DataSource = dt;
DataBind();