日期:2014-05-18 浏览次数:20779 次
………………………… public void ExportToExcel(Control ctrl, String FileName) { GridView gv = (GridView)ctrl; gv.AllowPaging = false;//清除分页 gv.AllowSorting = false;// 清除排序 GetExcel(); HttpContext.Current.Response.Charset = "GB2312"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName); HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Write(AddExcelHead()); StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); gv.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.Write(AddExcelbottom());//网格 HttpContext.Current.Response.End(); gv.AllowSorting = true; //恢复分页 gv.AllowPaging = true; //恢复排序 GetData2(); } public void GetExcel() { GridView2.DataSource = B_FileInfo1.GetExcle("'%,'+'" + Session["Townid"].ToString() + "'+',%' and b.townid='" + Session["Townid"].ToString() + "'" + " and FdataTime between '" + before.Value + "' and '" + later.Value + "'"); GridView2.DataBind(); } private void GetData2() { GridView2.DataSource = B_FileInfo1.GetExcle("'%,'+'" + Session["Townid"].ToString() + "'+',%' and b.townid='" + Session["Townid"].ToString() + "'" + " and FdataTime between '" + before.Value + "' and '" + later.Value + "'"); GridView2.DataBind(); } …………………………………… public override void VerifyRenderingInServerForm(Control control) { }
public override void VerifyRenderingInServerForm(Control control) { }