要全部展示數據,所以導出時要先將翻頁取消,重新綁定數據: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));
}
