asp.net實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫(kù)數(shù)據(jù)并導(dǎo)出Excel的方法
本文實(shí)例講述了asp.net實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫(kù)數(shù)據(jù)并導(dǎo)出Excel的方法。分享給大家供大家參考,具體如下:
protected void showData_Click(object sender, EventArgs e) { SqlConnection myConnection = new SqlConnection("Data Source=localhost;Initial Catalog=test;User ID=sa;password=sa"); SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM booklist", myConnection); DataSet ds = new DataSet(); ad.Fill(ds); this.gvShowData.DataSource = ds; this.gvShowData.DataBind(); } //導(dǎo)出Excel表 protected void btnExportToExcel_Click(object sender, EventArgs e) { Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.AddHeader("Content-Type", "application/vnd.ms-excel"); Response.AddHeader("Content-Disposition", "myexcelfile.xls"); //以此編碼模式導(dǎo)出才不會(huì)出現(xiàn)亂碼 StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gvShowData.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } //一定要寫(xiě),否則出錯(cuò)!! public override void VerifyRenderingInServerForm(Control control) { }
希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。
- asp.net實(shí)現(xiàn)數(shù)據(jù)從DataTable導(dǎo)入到Excel文件并創(chuàng)建表的方法
- asp.net頁(yè)面中如何獲取Excel表的內(nèi)容
- 直接在線預(yù)覽Word、Excel、TXT文件之ASP.NET
- asp.net中Table生成Excel表格的方法
- asp.net中EXCEL數(shù)據(jù)導(dǎo)入到數(shù)據(jù)庫(kù)的方法
- asp.net+ajax+sqlserver自動(dòng)補(bǔ)全功能實(shí)現(xiàn)解析
- asp.net(c#)實(shí)現(xiàn)從sqlserver存取二進(jìn)制圖片的代碼
- 快速插入大量數(shù)據(jù)的asp.net代碼(Sqlserver)
- ASP.NET下向SQLServer2008導(dǎo)入文件實(shí)例操作方法
- asp.net實(shí)現(xiàn)將Excel中多個(gè)sheet數(shù)據(jù)導(dǎo)入到SQLSERVER中的方法
相關(guān)文章
Asp.net MVC 中利用jquery datatables 實(shí)現(xiàn)數(shù)據(jù)分頁(yè)顯示功能
這篇文章主要介紹了Asp.net MVC 中利用jquery datatables 實(shí)現(xiàn)數(shù)據(jù)分頁(yè)顯示功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-06-06vb 中的MD5加密在asp.net中的實(shí)現(xiàn)
給定標(biāo)識(shí)哈希類(lèi)型的密碼和字符串,該例程產(chǎn)生一個(gè)適合存儲(chǔ)在配置文件中的哈希密碼,感興趣的朋友可以參考下本文2013-04-04Asp.Net?Core使用Ocelot結(jié)合Consul實(shí)現(xiàn)服務(wù)注冊(cè)和發(fā)現(xiàn)
這篇文章介紹了Asp.Net?Core使用Ocelot結(jié)合Consul實(shí)現(xiàn)服務(wù)注冊(cè)和發(fā)現(xiàn)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04ASP.NET Core根據(jù)環(huán)境變量支持多個(gè) appsettings.json配置文件
這篇文章主要介紹了ASP.NET Core根據(jù)環(huán)境變量支持多個(gè) appsettings.json配置文件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08asp.net 產(chǎn)生隨機(jī)顏色實(shí)現(xiàn)代碼
asp.net 隨機(jī)顏色產(chǎn)生實(shí)現(xiàn)代碼,需要的朋友拿過(guò)去測(cè)試一下。2009-11-11動(dòng)態(tài)ItemTemplate的實(shí)現(xiàn)(譯) - item,template
動(dòng)態(tài)ItemTemplate的實(shí)現(xiàn)(譯) - item,template...2007-02-02