在以下按鈕單擊事件中實(shí)現(xiàn):
private void btnmime_click(object sender, system.eventargs e)
{
binddata();
response.contenttype = "application/vnd.ms-excel";
response.addheader("content-disposition", "inline;filename="
+ httputility.urlencode("下載文件.xls",encoding.utf8 ) );
//如果輸出為word,修改為以下代碼
//response.contenttype = "application/ms-word"
//response.addheader("content-disposition", "inline;filename=test.doc")
stringbuilder sb=new stringbuilder();
system.io.stringwriter sw = new system.io.stringwriter(sb);
system.web.ui.htmltextwriter hw = new system.web.ui.htmltextwriter(sw);
sb.append("<html><body>");
dgshow.rendercontrol(hw);
sb.append("</body></html>");
response.write(sb.tostring());
response.end();
}
注:1.若datagrid中有按鈕列,則在導(dǎo)出前應(yīng)先將其隱藏.
2.若datagrid有分頁,而又要打印所有數(shù)據(jù)的話就應(yīng)先取消分頁.
新聞熱點(diǎn)
疑難解答
圖片精選