asp.net實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel的方法
本文實例講述了asp.net實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出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();
}
//導出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");
//以此編碼模式導出才不會出現(xiàn)亂碼
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvShowData.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
//一定要寫,否則出錯??!
public override void VerifyRenderingInServerForm(Control control)
{
}
希望本文所述對大家asp.net程序設計有所幫助。
- asp.net實現(xiàn)數(shù)據(jù)從DataTable導入到Excel文件并創(chuàng)建表的方法
- asp.net頁面中如何獲取Excel表的內容
- 直接在線預覽Word、Excel、TXT文件之ASP.NET
- asp.net中Table生成Excel表格的方法
- asp.net中EXCEL數(shù)據(jù)導入到數(shù)據(jù)庫的方法
- asp.net+ajax+sqlserver自動補全功能實現(xiàn)解析
- asp.net(c#)實現(xiàn)從sqlserver存取二進制圖片的代碼
- 快速插入大量數(shù)據(jù)的asp.net代碼(Sqlserver)
- ASP.NET下向SQLServer2008導入文件實例操作方法
- asp.net實現(xiàn)將Excel中多個sheet數(shù)據(jù)導入到SQLSERVER中的方法
相關文章
Asp.net MVC 中利用jquery datatables 實現(xiàn)數(shù)據(jù)分頁顯示功能
這篇文章主要介紹了Asp.net MVC 中利用jquery datatables 實現(xiàn)數(shù)據(jù)分頁顯示功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-06-06
Asp.Net?Core使用Ocelot結合Consul實現(xiàn)服務注冊和發(fā)現(xiàn)
這篇文章介紹了Asp.Net?Core使用Ocelot結合Consul實現(xiàn)服務注冊和發(fā)現(xiàn)的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04
ASP.NET Core根據(jù)環(huán)境變量支持多個 appsettings.json配置文件
這篇文章主要介紹了ASP.NET Core根據(jù)環(huán)境變量支持多個 appsettings.json配置文件,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-08-08
asp.net 產(chǎn)生隨機顏色實現(xiàn)代碼
asp.net 隨機顏色產(chǎn)生實現(xiàn)代碼,需要的朋友拿過去測試一下。2009-11-11
動態(tài)ItemTemplate的實現(xiàn)(譯) - item,template
動態(tài)ItemTemplate的實現(xiàn)(譯) - item,template...2007-02-02

