国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

解析ASP.NET頁面數據導出到Excel或Word_.Net教程

2024-07-10 12:51:53
字體:
來源:轉載
供稿:網友

推薦:解析簡單實用的DataGrid自定義分頁源程序
首先新建一個名為article.aspx的文件,將以下內容拷貝到article.aspx.cs中: usingSystem; usingSystem.Data; usingSystem.Configuration; usingSystem.Collections; usingSystem.Web; usingSystem.Web.Security; usingSystem.Web.UI; usingSystem.Web.UI.WebCo

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中有按鈕列,則在導出前應先將其隱藏. 
2.若DataGrid有分頁,而又要打印所有數據的話就應先取消分頁.

分享:詳解datalist的用法
設計模版: 頁眉 HeaderTemplate /HeaderTemplate 頁腳 FooterTemplate /FooterTemplate 數據記錄 ItemTemplate /ItemTemplate AlternatingItemTemplate交替顯示項 /AlternatingItemTemplate SelectedItemTemplate選中時的顯示方式 /SelectedItemTemplate Ed

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沛县| 华坪县| 常山县| 犍为县| 安龙县| 遂昌县| 寿光市| 霍州市| 垫江县| 咸阳市| 左云县| 米易县| 安徽省| 茶陵县| 安乡县| 龙川县| 吴江市| 满洲里市| 龙山县| 鹰潭市| 诏安县| 安龙县| 浪卡子县| 平安县| 鲁山县| 开远市| 民勤县| 德安县| 谷城县| 泉州市| 肇源县| 滨州市| 北流市| 衡山县| 射阳县| 灵寿县| 宜兴市| 汨罗市| 保山市| 台中市| 苏州市|