再做个补充:
如果在B里加个按钮,把Page_load里的代码写到这个按钮里
这个时候B可以显示,当击按钮,就要以弹出Excel的打开保存取消的消息框了.
但是直接写在page_load里就不行,不知道为什么???

解决方案 »

  1.   

    页面上增加这个就应该可以了
            public override void VerifyRenderingInServerForm(Control control)//重载控件 于server,for 导出excel
            {        }我的导出代码
            /// <summary>
            /// 从Gridview导入到Excel
            /// </summary>
            public static void ToExcel(GridView Gv, Page page, string filename)
            {
                if (Gv.Rows.Count > 0)
                {
                    page.Response.ClearContent();
                    page.Response.Charset = "UTF-8";
                    page.Response.ContentEncoding = System.Text.Encoding.UTF8;
                    page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, Encoding.UTF8).ToString());
                    page.Response.ContentType = "application/ms-excel";
                    StringWriter tw = new StringWriter();
                    HtmlTextWriter hw = new HtmlTextWriter(tw);
                    Gv.RenderControl(hw);
                    page.Response.Write(tw.ToString());
                    page.Response.End();
                }
            }
      

  2.   

    可能是浏览器设置问题
    我经常碰到
    你尝试按住Ctrl+"导出Excel按钮"
      

  3.   

    page_load结束后就会是页面的显示,而把打开保存取消的消息框给 屏蔽了
      

  4.   

    changke18:
    你说得没错,按住Ctrl就好用了
    但是不能让客户也一直按着Ctrl,你有什么好的解决办法吗?
      

  5.   

    为什么那么神奇,按住Ctrl键就一切正常了!求解释啊。我正遇到这个问题,不知道楼主解决了没有。救救小弟啊……