如果是gridview内容导出到excel的话,可以参考下面代码:
public partial class hxqExecl : System.Web.UI.Page
{
     protected void Page_Load(object sender, EventArgs e)
     {
         if (!IsPostBack)
             bind();
     }
     protected void Button1_Click(object sender, EventArgs e)
     {
         Response.Clear();
         Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
         Response.Charset = "gb2312";
         Response.ContentType = "application/vnd.xls";
         System.IO.StringWriter stringWrite = new System.IO.StringWriter();
         System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);         GridView1.AllowPaging = false;
         bind ();
         GridView1.RenderControl(htmlWrite);         Response.Write(stringWrite.ToString());
         Response.End();
         GridView1.AllowPaging = true;
         bind();
     }
     protected void bind()
     {
         string strConn, strSql;
         strConn = WebConfigurationManager.ConnectionStrings[2].ConnectionString;
         strSql = "select * from lgdjb where lgbs>'1100'";         SqlConnection sqlCon = new SqlConnection(strConn);
         SqlDataAdapter sqlDa = new SqlDataAdapter(strSql, sqlCon);
         DataSet ds = new DataSet();
         sqlDa.Fill(ds, "lgdjb");
         GridView1.DataSource = ds;
         GridView1.DataBind();
     }
     public override void VerifyRenderingInServerForm(Control control)
     {
         //base.VerifyRenderingInServerForm(control);
     }
}