用法: 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
}
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!


