在导出Excel数据时, 通过输出流导出, 但是弹出的下载窗口一闪而过. 问题代码如下:
<ext:GridPanel ID="SLGridPanel" runat="server" Title="查询结果" Margins="0 0 5 5" Height="600"
Icon="UserSuit" Region="Center" Frame="true" StripeRows="true" TrackMouseOver="true"
EnableHdMenu="true" EnableColumnHide="true">
<TopBar>
<ext:Toolbar ID="Toolbar2" runat="server">
<Items>
<ext:Button ID="Button5" runat="server" Text="To Excel" AutoPostBack="true" OnClick="btnToExcel_DirectClick"
Icon="PageExcel">
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
上面红色字体下载按钮控件的代码块, 必须放在GridPanel 控件中. 而GridPanel即是要到处的数据列表.
其次:
protected void btnToExcel_DirectClick(object sender, EventArgs e)
{
string strWhere = String.Empty;
if (Session["strWhere"] != null)
{
strWhere = Session["strWhere"].ToString();
}
IList<项目信息Info> resultDt = 项目信息dal.GetAll(strWhere);
string json = JsonConvert.SerializeObject(resultDt);
StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
XmlNode xml = eSubmit.Xml;
this.Response.Clear();
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls");
XslCompiledTransform xtExcel = new XslCompiledTransform();
xtExcel.Load(Server.MapPath("Excel.xsl"));
xtExcel.Transform(xml, null, this.Response.OutputStream);
this.Response.End();
}
函数参数必须是EventArgs类型, 否则出错.