ASP.net(gridview导出的execl没有数据)求解给分
/// <summary>
/// 显示所有数据到grid表
/// </summary>
private void displayLog()
{
this.gSysLos.DataSource = SysLogManager.GetAllSysLog();
this.gSysLos.DataBind();
}
protected void btnExportLog_Click(object sender, EventArgs e)
{
if (gSysLos.Rows.Count > 0)
{
//调用导出方法
ExportGridViewForUTF8(gSysLos, DateTime.Now.ToShortDateString() + ".xls");
}
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="GridView"></param>
/// <param name="filename">保存的文件名称</param>
private void ExportGridViewForUTF8(ExtAspNet.Grid GridView, string filename)
{
string attachment = "attachment; filename=" + filename;
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", attachment);
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}