标题:将 GridView 导出到 Excel 文件中
取消只看楼主
jalonlovesja
Rank: 5Rank: 5
来 自:湖南邵阳
等 级:职业侠客
帖 子:292
专家分:371
注 册:2008-2-19
结帖率:75%
 问题点数:0 回复次数:0 
将 GridView 导出到 Excel 文件中
protected void btnDaoChu_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.AddHeader("content-disposition","attachment;filename=FileName.xls");
        Response.Charset = "gb2312";
        Response.ContentType = "application/vnd.xls";
        StringWriter stringWrite = new StringWriter();
        HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        //GridView1.AllowPaging = false;
        //GridViewBind();
        GridView1.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
        //GridView1.AllowPaging = true;
        //GridViewBind();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@;");
        }
    }
请问我的代码哪里出错了,怎么运行怎么报了“一个只能在执行Render()的过程中调用......”我不知道哪里出错了
 请路过的朋友来看下了。
谢谢啊!!!
搜索更多相关主题的帖子: Excel GridView Response 文件 
2008-02-23 09:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-200677-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.409439 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved