主頁 > 知識庫 > asp.net實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel的方法

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

熱門標簽:地圖標注的公司有哪些 天心智能電銷機器人 地圖定位圖標標注 遂寧市地圖標注app 濮陽外呼電銷系統(tǒng)怎么樣 代理接電話機器人如何取消 地圖標注專業(yè)團隊 400電話辦理哪家性價比高 塔城代理外呼系統(tǒng)

本文實例講述了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表的內(nèi)容
  • 直接在線預覽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中的方法

標簽:婁底 河南 重慶 麗江 汕頭 吉林 宜春 本溪

巨人網(wǎng)絡通訊聲明:本文標題《asp.net實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel的方法》,本文關(guān)鍵詞  asp.net,實現(xiàn),Gradview,綁定,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel的方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章