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

首頁(yè) > 編程 > .NET > 正文

asp.net實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫(kù)數(shù)據(jù)并導(dǎo)出Excel的方法

2024-07-10 13:29:44
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

這篇文章主要介紹了asp.net實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫(kù)數(shù)據(jù)并導(dǎo)出Excel的方法,涉及asp.net操作Gradview實(shí)現(xiàn)數(shù)據(jù)庫(kù)綁定及數(shù)據(jù)導(dǎo)出的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了asp.net實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫(kù)數(shù)據(jù)并導(dǎo)出Excel的方法。分享給大家供大家參考,具體如下:

 

 
  1. protected void showData_Click(object sender, EventArgs e) 
  2. SqlConnection myConnection 
  3. new SqlConnection("Data Source=localhost;Initial Catalog=test;User ID=sa;password=sa"); 
  4. SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM booklist", myConnection); 
  5. DataSet ds = new DataSet(); 
  6. ad.Fill(ds); 
  7. this.gvShowData.DataSource = ds; 
  8. this.gvShowData.DataBind(); 
  9. //導(dǎo)出Excel表 
  10. protected void btnExportToExcel_Click(object sender, EventArgs e) 
  11. Response.Charset = "GB2312"
  12. Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); 
  13. Response.AddHeader("Content-Type""application/vnd.ms-excel"); 
  14. Response.AddHeader("Content-Disposition""myexcelfile.xls"); 
  15. //以此編碼模式導(dǎo)出才不會(huì)出現(xiàn)亂碼 
  16. StringWriter sw = new StringWriter(); 
  17. HtmlTextWriter htw = new HtmlTextWriter(sw); 
  18. gvShowData.RenderControl(htw); 
  19. Response.Write(sw.ToString()); 
  20. Response.End(); 
  21. //一定要寫,否則出錯(cuò)!! 
  22. public override void VerifyRenderingInServerForm(Control control) 

希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到ASP.NET教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 耿马| 新蔡县| 汕头市| 政和县| 怀柔区| 梅河口市| 防城港市| 平湖市| 连云港市| 洛川县| 临江市| 聂拉木县| 嘉义县| 峨山| 海原县| 金阳县| 洛阳市| 太保市| 高阳县| 类乌齐县| 阜宁县| 汉寿县| 南木林县| 昌黎县| 临汾市| 武夷山市| 佛坪县| 荥经县| 北票市| 馆陶县| 石阡县| 蕉岭县| 武城县| 新闻| 邻水| 类乌齐县| 清徐县| 海盐县| 文安县| 开封县| 泰安市|