在我的 aspx 页面上,我有一个Usercontrol
包含 的Gridview
,它的数据是根据从 aspx 页面传递到 UserControl 的参数动态加载的,我称之为QuotesReport1
.
导出运行时,它只将布局导出到 中Spreadsheet
,而没有任何 gridview 的数据,例如:
<style>
body
{
margin: 0px;
}
</style>
<div>
</div>
我的导出代码是:
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) { }
在 UserControl 内部,运行 SQL 查询,该查询返回一个 DataTable,然后将其绑定到 UserControl 内部的 Gridview,大致如下:
SQLData da = new SQLData();
GridView1.DataSource = da.SGetDataTable(query);
GridView1.DataBind();