在其它浏览器上都是可以导出的,但是在IE6下不能导出
你选择保存,提示internet explorer 无法下载
无法找到路径或者路径错误
选择打开的话,就弹出一个安装提示,等待的提示,一会儿以后就报错了

解决方案 »

  1.   

    楼主肯定少了一个重要的方法:
     public override void VerifyRenderingInServerForm(Control control)//必须有这个方法
        {    }下面是完整的例子:1//注意引入IO空间
     using System.IO;
     
    2(1)在源代码<page>里中加入:EnableEventValidation = "false" 
     (2) public void ExcelOut(GridView gv)
        {//导出Excel表的方法
            if (gv.Rows.Count > 0)
            {//有数据行
                Response.Clear();
                Response.ClearContent();
                Response.AddHeader("Content-Disposition","attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");//以系统时间设置为文件名
                Response.ContentEncoding = System.Text.Encoding.UTF8;//UTF8编码
                Response.ContentType = "application/ms-excel";//文件类型
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                gv.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.Flush();
                Response.End();//结束
            }
            else
            {
               Response.Write("没有数据记录");
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {//导出按钮事件
            ExcelOut(GridView1);//调用方法
        }
        public override void VerifyRenderingInServerForm(Control control)//必须有这个方法
        {    }