⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 导出gridview到excel中.txt

📁 ASP.NET学习大全(高手整理)。。。。。。。。。。。共同学习
💻 TXT
字号:
导出GridView到Excel中    
    
 


导出GridView到Excel中的关键之处

用法: ToExcel(GVStaff, TextBox1.Text);

public static void ToExcel(System.Web.UI.Control ctl,string FileName)
        {
            HttpContext.Current.Response.Charset ="UTF-8";
            HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentType ="application/ms-excel";
            HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+""+FileName+".xls");
            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();
        }        
     
必须有下面这句!否则不会通过!
public override void VerifyRenderingInServerForm(Control control)
    {
        // Confirms that an HtmlForm control is rendered for
    }  


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -