////// 导出按钮/// /// /// protected void btnExport_Click1(object sender, EventArgs e){ this.gv.AllowPaging = false; this.gv.AllowSorting = false; Query();//获取数据并绑定到GridView toExcel(this.gv); this.gv.AllowPaging = true; this.gv.AllowSorting = true; Query();//获取数据并绑定到GridView}////// 导出到Excel/// /// void toExcel(GridView gv){ Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); string fileName = "export.xls"; string style = @"
备注:
1、gv就是页面上的GridView空间名称;
2、代码中的Query方法所做的是,获取数据并绑定到GridView。