日期:2014-05-18  浏览次数:20779 次

GridView导出Excel数据为空,紧急求助
代码如下:

C# code
…………………………
public void ExportToExcel(Control ctrl, String FileName)
    {
        GridView gv = (GridView)ctrl;
        gv.AllowPaging = false;//清除分页 
        gv.AllowSorting = false;// 清除排序
        GetExcel();
        HttpContext.Current.Response.Charset = "GB2312";
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
        HttpContext.Current.Response.ContentType = "application/ms-excel";
        HttpContext.Current.Response.Write(AddExcelHead());
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        gv.RenderControl(hw);
        HttpContext.Current.Response.Write(tw.ToString());
        HttpContext.Current.Response.Write(AddExcelbottom());//网格
        HttpContext.Current.Response.End();
        gv.AllowSorting = true; //恢复分页 
        gv.AllowPaging = true; //恢复排序 
        GetData2();
    }
public void GetExcel()
    {
        GridView2.DataSource = B_FileInfo1.GetExcle("'%,'+'" + Session["Townid"].ToString() + "'+',%' and b.townid='" + Session["Townid"].ToString() + "'" + " and FdataTime between '" + before.Value + "' and '" + later.Value + "'");
        GridView2.DataBind();
    }
private void GetData2()
    {
        GridView2.DataSource = B_FileInfo1.GetExcle("'%,'+'" + Session["Townid"].ToString() + "'+',%' and b.townid='" + Session["Townid"].ToString() + "'" + " and FdataTime between '" + before.Value + "' and '" + later.Value + "'");
        GridView2.DataBind();
    }
……………………………………
public override void VerifyRenderingInServerForm(Control control)
    {
    }



调试了一下,发现是以下代码没有运行
C# code
public override void VerifyRenderingInServerForm(Control control)
    {
    }


如何让上面的代码运行?

------解决方案--------------------
你是如何调用的?没有调用,肯定不会Run.