婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 如何將數(shù)據(jù)綁到gridview然后導成excel

如何將數(shù)據(jù)綁到gridview然后導成excel

熱門標簽:宿遷智能外呼系統(tǒng)排名 怎樣給陜西地圖標注顏色 400電話辦理信任翰諾科技 ai電銷機器人對貸款有幫助嗎 福州人工智能電銷機器人加盟 廣州銷售外呼系統(tǒng)定制 地圖標注多少錢一張 電銷機器人 數(shù)據(jù) 云狐人工智能電話機器人
復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data .SqlClient ;
using System.Data ;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String sqlconn = "Server=.; DataBase=db; Integrated Security=SSPI ";
string sql = "select top 10 * from table";

SqlConnection myConnection = new SqlConnection(sqlconn);// 創(chuàng)建數(shù)據(jù)庫連接實例

myConnection.Open(); //打開數(shù)據(jù)庫

SqlCommand myCommand = new SqlCommand(sql, myConnection);//創(chuàng)建sql的實例,執(zhí)行一個sql


SqlDataAdapter Adapter = new SqlDataAdapter();//創(chuàng)建一個sql數(shù)據(jù)適配器
Adapter.SelectCommand = myCommand;//屬性設置為 從數(shù)據(jù)源中檢索記錄


DataSet myDs = new DataSet(); //創(chuàng)建數(shù)據(jù)集實例
Adapter.Fill(myDs);//填充數(shù)據(jù)集

GridView1.DataSource = myDs.Tables[0].DefaultView;//
GridView1.DataBind();

// DataToExcel("測試的cxcel", GridView1);
myConnection.Close();//關(guān)閉數(shù)據(jù)庫連接
}
public void DataToExcel(string fileName, GridView myGridView)
{
//定義文檔類型、字符編碼
Response.Clear();
Response.Buffer = false;
//Response.Charset = "utf-8";
Response.Charset = "GB2312";
//下面這行很重要, attachment 參數(shù)表示作為附件下載,您可以改成 online在線打開
//filename=FileFlow.xls 指定輸出文件的名稱,注意其擴展名和指定文件類型相符,可以為:.doc || .xls || .txt ||.htm
Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + ".xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
//Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//Response.ContentType指定文件類型 可以為application/ms-excel || application/ms-word || application/ms-txt || application/ms-html || 或其他瀏覽器可直接支持文檔
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
//System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
//定義一個輸入流
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
//將目標數(shù)據(jù)綁定到輸入流輸出
myGridView.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}

//下面這個空語句一定要加,否則會出現(xiàn)“必須放在具有 runat=server 的窗體標記內(nèi)。”的錯誤
public override void VerifyRenderingInServerForm(Control control)
{
}

//點擊事件,生成excel
protected void Button1_Click(object sender, EventArgs e)
{
DataToExcel("測試的cxcel", GridView1);
}
}
您可能感興趣的文章:
  • WinForm中DataGridView添加,刪除,修改操作具體方法
  • WinForm DataGridView控件隔行變色的小例子
  • asp.net中的GridView分頁問題
  • gridview生成時如何去掉style屬性中的border-collapse
  • C#使用RenderControl將GridView控件導出到EXCEL的方法
  • asp.net遍歷文件夾下所有子文件夾并綁定到gridview上的方法
  • asp.net讀取excel中的數(shù)據(jù)并綁定在gridview
  • Winform中GridView分組排序功能實現(xiàn)方法

標簽:曲靖 焦作 綿陽 宜春 新疆 黃南 延安 大興安嶺

巨人網(wǎng)絡通訊聲明:本文標題《如何將數(shù)據(jù)綁到gridview然后導成excel》,本文關(guān)鍵詞  如何,將,數(shù)據(jù),綁,到,gridview,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《如何將數(shù)據(jù)綁到gridview然后導成excel》相關(guān)的同類信息!
  • 本頁收集關(guān)于如何將數(shù)據(jù)綁到gridview然后導成excel的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 澄江县| 盐边县| 东港市| 杂多县| 兴海县| 清水河县| 荆州市| 拉萨市| 曲麻莱县| 平阴县| 湖州市| 离岛区| 娄烦县| 达拉特旗| 赫章县| 勃利县| 梅州市| 磴口县| 西峡县| 板桥市| 禹州市| 盐亭县| 穆棱市| 张家界市| 松桃| 长泰县| 德庆县| 新邵县| 韶山市| 东宁县| 宝鸡市| 札达县| 德安县| 盐山县| 新津县| 封丘县| 正宁县| 饶河县| 班戈县| 浦县| 游戏|