| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 772 人关注过本帖
标题:将 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
快速回复:将 GridView 导出到 Excel 文件中
数据加载中...
 
   



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

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