• gridview导excel及解决导出中文乱码的方法


    要全部展示数据,所以导出时要先将翻页取消,重新绑定数据:gridview的allowpaging属性设置为false,然后databind()一下

    <%@ Page Language="C#" EnableEventValidation = "false" AutoEventWireup="true" CodeFile="SysUser.aspx.cs" Inherits="Autho_SysUser2" %>

    添加方法:

    public override void VerifyRenderingInServerForm(Control control)
    {
    }

    private void ToExcel(Control ctl, string FileName)
    {
    HttpContext.Current.Response.Charset = "UTF-8";
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
    HttpContext.Current.Response.ContentType = "application/ms-excel";
    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
    ctl.Page.EnableViewState = false;
    System.IO.StringWriter tw = new System.IO.StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(tw);
    ctl.RenderControl(hw);
    HttpContext.Current.Response.Write(tw.ToString());
    HttpContext.Current.Response.End();
    }

    protected void btnCheck0_Click(object sender, EventArgs e)
    {
    grdlogin.AllowPaging = false;
    if (tbxXingming.Text != "")
    {
    BllImslog bllimslog = new BllImslog();
    grdlogin.DataSource = bllimslog.GetRequestLog(tbxXingming.Text, ddlLoginsitu.SelectedValue, tbxStime.Text, tbxEtime.Text);
    grdlogin.DataBind();
    }
    else
    {
    BindData();
    }
    ToExcel(this.grdlogin, System.Web.HttpUtility.UrlEncode("IMS登陆情况报表.xls", System.Text.Encoding.UTF8));

    }

  • 相关阅读:
    JS字符串之字符方法
    JS数组之归并方法
    JS数组之迭代方法
    JS数组之位置方法
    JS数组之操作方法
    【Vue-入门笔记-3】
    【Vue-入门笔记-2】
    阿里靠什么武功秘籍渡过“双十一“的天量冲击
    CC++ --- 线性表-学生成绩管理系统
    TortoiseSVN 使用教程
  • 原文地址:https://www.cnblogs.com/windphoenix/p/3185949.html
Copyright © 2020-2023  润新知