asp.net實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫(kù)數(shù)據(jù)并導(dǎo)出Excel的方法
更新時(shí)間:2015年11月25日 11:51:19 作者:一只小青蛙
這篇文章主要介紹了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的方法。分享給大家供大家參考,具體如下:
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();
}
//一定要寫,否則出錯(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開發(fā)之webform圖片水印和圖片驗(yàn)證碼的實(shí)現(xiàn)方法
這篇文章主要介紹了Asp.net開發(fā)之webform圖片水印和圖片驗(yàn)證碼的實(shí)現(xiàn)方法,實(shí)現(xiàn)思路分為前后臺(tái)代碼和效果展示,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
Silverlight融合ajax實(shí)現(xiàn)前后臺(tái)數(shù)據(jù)交互
兩年前Silverlight 還未起名,故事發(fā)生在WPF/E 的年代里。07年8月在中軟實(shí)習(xí)時(shí),我承擔(dān)起了在. Net 中嵌入WPF/E 的任務(wù),目的是增強(qiáng)用戶體驗(yàn)。2009-05-05
剖析ASP.NET MVC的DependencyResolver組件
這篇文章主要為大家剖析ASP.NET MVC的DependencyResolver組件,感興趣的小伙伴們可以參考一下2016-04-04
ASP.NET Core實(shí)現(xiàn)文件上傳和下載
這篇文章主要為大家詳細(xì)介紹了ASP.NET Core實(shí)現(xiàn)文件上傳和下載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07

