最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2015年11月25日 11:51:19   作者:一只小青蛙  
這篇文章主要介紹了asp.net實現(xiàn)Gradview綁定數(shù)據(jù)庫數(shù)據(jù)并導出Excel的方法,涉及asp.net操作Gradview實現(xiàn)數(shù)據(jù)庫綁定及數(shù)據(jù)導出的相關(guān)技巧,非常簡單實用,需要的朋友可以參考下

本文實例講述了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程序設(shè)計有所幫助。

相關(guān)文章

最新評論

天祝| 观塘区| 宣化县| 乌拉特后旗| 孟村| 鄱阳县| 巨野县| 沂南县| 丽水市| 阳城县| 皮山县| 翼城县| 宜君县| 颍上县| 甘泉县| 楚雄市| 顺义区| 灵川县| 巍山| 嫩江县| 康乐县| 德阳市| 赫章县| 龙口市| 平潭县| 遂川县| 讷河市| 高要市| 昭苏县| 耿马| 麻江县| 汉川市| 恩施市| 东辽县| 北川| 手机| 肇庆市| 屯留县| 伊川县| 阜宁县| 彰武县|