1、在aspx頁面page標記中設定enableeventvalidation屬性
<%@ page language="c#"enableeventvalidation = "false"autoeventwireup="true" codefile="operationloglist.aspx.cs"
inherits="usermanage_operationloglist" %>
2、匯出資料到excel
response.clear();
response.buffer = true;
response.charset = "gb2312";
// 如果設定為 getencoding("gb2312");匯出的檔案將會出現亂碼!!!
response.contentencoding = system.text.encoding.utf8;
system.io.stringwriter ostringwriter = new system.io.stringwriter();
system.web.ui.htmltextwriter ohtmltextwriter = new system.web.ui.htmltextwriter(ostringwriter);
// 設定gridview控制項不可以分頁,繫結資料,匯出資料到excel
this.gvloglist.allowpaging = false;
execquery();
this.gvloglist.rendercontrol(ohtmltextwriter);
response.output.write(ostringwriter.tostring());
response.flush();
response.end();
// 設定gridview控制項可以分頁,重新繫結資料
this.gvloglist.allowpaging = true;
execquery();
3、重寫方法verifyrenderinginserverform(),必須有,方法體為空就可以。
public override void verifyrenderinginserverform(control control)
使用GridView將資料匯入或匯出Excel中
preclass csharp name code using system using system.collections using system.configuration using system.data using system.linq using system.web using ...
gridview 匯出資料到Excel 方案
protected void button1 click object sender,eventargs e protected void button2 click object sender,eventargs e public override void verifyrenderinginse...
GridView匯出資料到Excel時格式設定
一 excel的格式 1 文字 vnd.ms excel.numberformat 2 日期 vnd.ms excel.numberformat yyyy mm dd 3 數字 vnd.ms excel.numberformat 0.00 4 貨幣 vnd.ms excel.numberformat...