On my aspx page, I have a Usercontrol which contains a Gridview, whose data is loaded dynamically based on params passed from the aspx page to the UserControl, which I called QuotesReport1.
When the export runs, it only exports the layout into the Spreadsheet, and none of the gridview's data, for example:
<style>
body
{
margin: 0px;
}
</style>
<div>
</div>
My code for the export is:
protected void Page_Load(object sender, EventArgs e)
{
string toDate = "";
string fromDate = "";
toDate = Request.QueryString.Get("toDate");
fromDate = Request.QueryString.Get("fromDate");
QuotesReport1.ToDate = DateTime.Parse(toDate);
QuotesReport1.FromDate = DateTime.Parse(fromDate);
QuotesReport1.Status = QuotesReport.quoteStatus.PENDING_REVIEW;
string attachment = "attachment; filename=Quotes_Pending.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
QuotesReport1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control) { }
Inside the UserControl, a SQL query runs, which returns a DataTable, which is then bound to the Gridview inside the UserControl, something along the lines of:
SQLData da = new SQLData();
GridView1.DataSource = da.SGetDataTable(query);
GridView1.DataBind();