现在是做一个excel导出,但是导出后无数据,请问各位大侠该怎么解决 protected void Button2_Click(object sender, EventArgs e)
{
try
{
string time = System.DateTime.Now.ToString();
this.Export("application/ms-excel", "" + time + ".xls");
}
catch
{ }
}
public override void VerifyRenderingInServerForm(Control control)
{ }
private void Export(string FileType, string FileName)
{
try
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GVSHOW.RenderControl(hw);
Response.Write(tw.ToString());
Response.End(); }
catch
{ }
}
这段代码有的页面可以使用但是在新做的几个页面中就不能用了
{
try
{
string time = System.DateTime.Now.ToString();
this.Export("application/ms-excel", "" + time + ".xls");
}
catch
{ }
}
public override void VerifyRenderingInServerForm(Control control)
{ }
private void Export(string FileType, string FileName)
{
try
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GVSHOW.RenderControl(hw);
Response.Write(tw.ToString());
Response.End(); }
catch
{ }
}
这段代码有的页面可以使用但是在新做的几个页面中就不能用了
GVSHOW.DataBind();
GVSHOW.RenderControl(hw);