這篇文章主要介紹“asp.net怎么實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導(dǎo)出Excel”,在日常操作中,相信很多人在asp.net怎么實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導(dǎo)出Excel問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”asp.net怎么實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導(dǎo)出Excel”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
本文實(shí)例講述了asp.net實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫數(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)出才不會出現(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) { }
到此,關(guān)于“asp.net怎么實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導(dǎo)出Excel”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
文章題目:asp.net怎么實(shí)現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導(dǎo)出Excel-創(chuàng)新互聯(lián)
鏈接地址:http://aaarwkj.com/article26/dopdjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、靜態(tài)網(wǎng)站、網(wǎng)站維護(hù)、外貿(mào)網(wǎng)站建設(shè)、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容