您好,登錄后才能下訂單哦!
這篇文章主要介紹“asp.net怎么實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel”,在日常操作中,相信很多人在asp.net怎么實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”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怎么實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。