欢迎光临
我们一直在努力

导出GridView到Excel中-.NET教程,数据库应用

建站超值云服务器,限时71元/月

导出gridview到excel中的关键之处
用法: toexcel(gvstaff, textbox1.text);

public static void toexcel(system.web.ui.control ctl,string filename)
        {
            httpcontext.current.response.charset =”utf-8″;
            httpcontext.current.response.contentencoding =system.text.encoding.default;
            httpcontext.current.response.contenttype =”application/ms-excel”;
            httpcontext.current.response.appendheader(“content-disposition”,”attachment;filename=”+””+filename+”.xls”);
            ctl.page.enableviewstate =false;
            system.io.stringwriter  tw = new system.io.stringwriter();
            htmltextwriter hw = new htmltextwriter(tw);
            ctl.rendercontrol(hw);
            httpcontext.current.response.write(tw.tostring());
            httpcontext.current.response.end();
        }       
    
必须有下面这句!否则不会通过!
public override void verifyrenderinginserverform(control control)
    {
        // confirms that an htmlform control is rendered for
    }

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 导出GridView到Excel中-.NET教程,数据库应用
分享到: 更多 (0)