码迷,mamicode.com
首页 > 其他好文 > 详细

girdView数据导出Excel

时间:2015-08-29 13:58:18      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>
    /// 导出分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExport_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
        Response.Charset = "gb2312";
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        gvScenic.AllowPaging = false;
        bindData();
        gvScenic.RenderControl(htmlWrite);

        Response.Write(stringWrite.ToString());
        Response.End();
        gvScenic.AllowPaging = true;
        bindData();
    }

加入form=ruanserver验证,否则报错

public override void VerifyRenderingInServerForm(Control control)
    {

    }

前台页面加入

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="testtest" EnableEventValidation = "false" %>
EnableEventValidation = "false"

girdView数据导出Excel

标签:

原文地址:http://www.cnblogs.com/ilooking/p/4768896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!