#region 导出Excel方法
//导出到Excel按钮
protected void btnExport_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "字段数据.xls"); } private void Export(string FileType, string FileName)
{
//清楚分页
gridView.AllowPaging = false;
BindData(); Response.Clear();
Response.Buffer = true;
//设定输出的字符集
Response.Charset = "GB2312";
//解决导出到Excel2007乱码问题
Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>"); //假定导出的文件名为盘点结果表.xls
Response.AppendHeader("Content-Disposition", "attachment;filename=" +
HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
//解决导出到Excel2007乱码问题
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置导出文件的格式
Response.ContentType = FileType;
//关闭ViewState
this.EnableViewState = false;
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter);
gridView.RenderControl(textWriter);
//把HTML写回浏览器
Response.Write(stringWriter.ToString());
Response.Flush();
Response.End();
gridView.AllowPaging = true;//恢复分页
//为GridView重新绑定数据源
BindData(); } //如果没有下面方法会报错,类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内(导出Excel或Word用)
public override void VerifyRenderingInServerForm(Control control)
{ }
#endregion

C# gridview分頁導出excel的更多相关文章

  1. GridView導出Excel

    1.aspx頁面需要添加:EnableEventValidation="false" 實例:<%@ Page Language="C#" AutoEven ...

  2. ASP.NET MVC 5 實作 GridView 分頁

    本文用 ASP.NET MVC 5 實作一個 GridView,功能包括: 分頁(paging).關鍵字過濾(filtering).排序(sorting).AJAX 非同步執行,外觀上亦支援 Resp ...

  3. Gridview分頁保存選項

    #region //'Revision: 1.00 Created Date: 2013/08/02 Created ID: Una [#1300071]增加多選框 /// <summary&g ...

  4. GridView導出Excel 解決亂碼問題

    Response.Clear(); Response.Charset = "gb2312"; Response.Buffer = true; Response.AddHeader( ...

  5. C#根據當前DataGridView查詢數據導出Excel

    private void btnsuggestinfo_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.C ...

  6. 導出Excel方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  7. Saiku更改導出文件的文件名(十九)

    Saiku更改導出文件的文件名 Saiku查询完数据之后,可以以excel,pdf,csv等格式将数据导出,这里我们来讲一下怎么更改导出的文件名. 找到对应的导出方法所在的js文件: saiku-se ...

  8. 使用LINQ 對List分頁/區

    listview之類的服務器控件分頁自不用多說,拖拖控件改改屬性分分鐘的事.就不浪費大家時間了.   這裏只寫大概思路及關鍵代碼了.   LINQ裏有一個對集合進行分區的操作可用於分頁.   page ...

  9. thinkphp5ajax分頁&&搜索後分頁

    //控制器層 //分頁 public function list_january_table(){ //設置當前頁 $page = input("post.page") ? inp ...

随机推荐

  1. Android中moveTo、lineTo、quadTo、cubicTo、arcTo详解(实例)

    1.Why 最近在写android画图经常用到这几个什么什么To,一开始还真不知道cubicTo这个方法,更不用说能不能分清楚它们了,所以特此来做个小笔记,记录下moveTo.lineTo.quadT ...

  2. sqlite3使用入门

    sqlite的安装 1. 首先是下载sqlite,可以该页面下载:http://www.sqlite.org/download.html 当前的最新版本为:sqlite-shell-win32-x86 ...

  3. Spark RCFile的那些“坑”

    RCFile在平台的应用场景中多数用于存储需要“长期留存”的数据文件,在我们的实践过程中,RCFile的数据压缩比通常可以达到8 : 1或者10 : 1,特别适用于存储用户通过Hive(MapRedu ...

  4. C#调用Web Service时的身份验证

    原理:webservice所在的系统中,在系统域中建立用于登录的软件的用户和密码,软件登录时将用户名.密码和登录的本机的域的名字通过webService的NetworkCredential传递到web ...

  5. Quality in the Test Automation Review Process and Design Review Template

    About this document Prerequisite knowledge/experience: Software Testing, Test Automation Applicable ...

  6. 实现自己的脚本语言ngscript之零

    正式开始介绍前先扯点没用的. 从小玩basic长大的小朋友大多有一个梦想,就是自己实现一个basic解释器. 不过这里我实现的不是basic,而是一个语法和功能类似javascript的东西. 暂且称 ...

  7. 趣解curl

    Curl是Linux下一个很强大的http命令行工具,其功能十分强大. 1) 二话不说,先从这里开始吧! $ curl http://www.linuxidc.com 回车之后,www.linuxid ...

  8. Python自带的日志模块logging的使用

    import logging     # 创建一个logger logger = logging.getLogger('cmccLogger') logger.setLevel(logging.DEB ...

  9. web项目学习之spring-security

    转自<http://liukai.iteye.com/blog/982088> spring security功能点总结: 1. 登录控制 2. 权限控制(用户菜单的显示,功能点访问控制) ...

  10. winform 窗体关闭按钮禁用、不显示最大化、最小化、关闭按钮 分类: WinForm 2014-12-22 16:09 82人阅读 评论(0) 收藏

    关闭按钮禁用: (1) FormClosing事件 private void Main_FormClosing(object sender, FormClosingEventArgs e) {     ...